﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Configuration;
using System.Text;
using ElingOA6_Admin_DSJCJ.Common;

namespace ElingOA6_Admin_DSJCJ.Areas.Admin.Controllers
{
    public class DocInfoOrderController : Controller
    {
        /// <summary>
        /// 信息排行榜
        /// </summary>
        [OutputCache(Duration = 0, VaryByParam = "none")]  
        public ActionResult Index(string year="",string quarter="",string type="ht")
        {
            BLL.DocClsScore docClsScoreBll = new BLL.DocClsScore();

            //单位编号
            string strEntityNo = ConfigurationManager.AppSettings["EntityNo"].ToString();

            //绑定年度
            List<SelectListItem> items = new List<SelectListItem>();
            DataSet ds = docClsScoreBll.getYears(strEntityNo);
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    items.Add(new SelectListItem() { Text = row["FYear"].ToString(), Value = row["FYear"].ToString() });
                }
            }
            ViewData["FYearSelection"] = items;
            if (year == "" || year == null)
            {
                year = items[0].Value;
            }
            ViewData["FYearSelected"] = year;

            //绑定季度
            items = new List<SelectListItem>();
            items.Add(new SelectListItem() { Text = "全年", Value = "0" });
            items.Add(new SelectListItem() { Text = "一季度", Value = "1" });
            items.Add(new SelectListItem() { Text = "二季度", Value = "2" });
            items.Add(new SelectListItem() { Text = "三季度", Value = "3" });
            items.Add(new SelectListItem() { Text = "四季度", Value = "4" });
            ViewData["quarterSelection"] = items;
            if (quarter == "" || quarter == null)
            {
                quarter = "0";
            }
            ViewData["quarterSelected"] = quarter;

            //生成信息排行榜
            
            decimal decYear = decimal.Parse(year);
            decimal decQuarter = decimal.Parse(quarter);
            string strQuarter = GetStrQuarter(decYear, decQuarter);//生成录用季度Where语句strQuarter
            string strQuarterOther = GetStrQuarterOther(decYear,decQuarter);//生成投稿季度Where语句strQuarter
            ViewData["tbDocInfoOrder"] = CreateDocInfoOrder(strEntityNo, decYear, decQuarter, strQuarter, strQuarterOther, type);
            
            return View();
        }

        //产生当前部门的信息明细
        public ActionResult DocInfoOrderDeptDetail(string deptNo, decimal year, decimal decQuarter)
        {
            //单位编号
            string strEntityNo = ConfigurationManager.AppSettings["EntityNo"].ToString();
            List<string> strList = CreateDocInfoDeptDetail(strEntityNo, decQuarter, deptNo, year);
            if (strList[0] != "" && strList[0] != null)
            {
                ViewData["chkLocal"] = strList[0];
            }
            else
            {
                ViewData["chkLocal"] = "";
            }
            if (strList[1] != "" && strList[1] != null)
            {
                ViewData["chkSuper"] = strList[1];
            }
            else
            {
                ViewData["chkSuper"] = "";
            }
            ViewData["year"] = year;
            ViewData["quarter"] = decQuarter;
            return View("DocInfoOrderDeptDetail");
        }

        //产生信息排行榜
        private string CreateDocInfoOrder(string strEntityNo, decimal decYear, decimal decQuarter, string strQuarter, string strQuarterOther, string type)
        {
            #region 需要用到的数据
            BLL.Document docBll = new BLL.Document();
            BLL.DocCls docClsBll = new BLL.DocCls();
            BLL.DocClsScore docClsScoreBll = new BLL.DocClsScore();
            BLL.ChkInfoCls chkInfoClsBll = new BLL.ChkInfoCls();
            BLL.HRDept deptBll = new BLL.HRDept();
            BLL.DocumentUnionPubEmpl docUnionPubEmplBll = new BLL.DocumentUnionPubEmpl();
            BLL.ChkInfoAuditManual chkInfoAuditManualBll = new BLL.ChkInfoAuditManual();
            BLL.ChkInfoStdLocal chkInfoStdLocalBll = new BLL.ChkInfoStdLocal();
            BLL.ChkInfoStdSuper chkInfoStdSuperBll = new BLL.ChkInfoStdSuper();

            List<Model.Document> listDoc = docBll.getDocByScore(strEntityNo, decYear, strQuarter.Replace("FPubDate", "FDisplayDate"));//获得所有需要考核的信息(已录用，未删除，信息考核分已定义)

            List<Model.Document> listDocAll = docBll.getDocByScoreAll(strEntityNo, decYear, strQuarterOther);//获得所有需要考核的信息(包括未录用),主要用于统计投稿数量

            List<Model.DocCls> listDocCls = docClsBll.getDocClsByScore(strEntityNo, decYear);//获得区级考核信息栏目(信息考核分定义里有定义过的。)
            List<Model.DocClsScore> listDocClsScore = docClsScoreBll.getListByYearAndIsScore(strEntityNo, decYear);//获得区级考核信息栏目考核分定义

            List<Model.ChkInfoCls> listChkInfoCls = chkInfoClsBll.GetListByYear(strEntityNo, decYear);//获得上级录用栏目信息
            List<Model.ChkInfoAuditManual> chkInfoAuditManual = chkInfoAuditManualBll.GetListByYear(strEntityNo, decYear, strQuarter.Replace("FPubDate", "FAuditDate"));//获得上级录用信息明细
            List<Model.ChkInfoStdLocal> listChkInfoStdLocal = chkInfoStdLocalBll.GetListByYear2(strEntityNo, decYear);//获取所有区本级录用的基分和部门编号
            List<Model.ChkInfoStdSuper> listChkInfoStdSuper = chkInfoStdSuperBll.GetListByYear2(strEntityNo, decYear);//获取上级录用的基分和部门编号

            List<Model.HRDept> listDeptAll = deptBll.GetDeptListAll(strEntityNo);//获取所有部门信息（包括虚拟部门）
            List<Model.HRDept> listDeptNoVirtual = deptBll.getDeptListNoVirtual(strEntityNo, decYear);//获取部门信息,不包括虚拟部门

            List<Model.Document> listDocHF = docBll.GetDocByHF(strEntityNo, strQuarter.Replace("FPubDate", "FDisplayDate"));//获取有合发情况的信息(已录用，未删除)
            List<Model.Document> listDocHFAll = docBll.GetDocByHFAll(strEntityNo, strQuarterOther);//获取有合发情况的信息(包括未录用，未删除)
            List<Model.DocumentUnionPubEmpl> documentUnionPubEmplList = docUnionPubEmplBll.GetModelList_DocIdAndDeptNo("");//合发数据根据FDocId,FDeptNo分组，用于查询某文档的所有部门编号

            string strLocalDocClsCd = string.Empty;//需要计算的区局录用信息类别编号
            string strLocalDocClsName = string.Empty;//需要计算的区局录用信息类别名称

            //获取专题专栏及其子类栏目的编号
            List<string> ztzlDocClsCdList = (from c in listDocCls
                                             where c.FDocClsCd == "100" || c.FPreDocClsCd == "100"
                                             select c.FDocClsCd).ToList();







            //临时
            listDeptNoVirtual = (from c in listDeptNoVirtual
                                 where c.FDeptNo != "213"
                                 select c).ToList();

            foreach (Model.Document model in listDoc)
            {
                if (model.FDeptNo == "213")
                {
                    model.FDeptNo = "218";
                }
            }

            foreach (Model.Document model in listDocAll)
            {
                if (model.FDeptNo == "213")
                {
                    model.FDeptNo = "218";
                }
            }

            #endregion

            StringBuilder sbr = new StringBuilder();

            #region 绑定标题行

            //第一行
            sbr.Append("<tr>");
            sbr.Append("<td align=\"center\" rowspan=\"2\" class=\"tdText\" width=\"30px\">排序</td>");
            sbr.Append("<td align=\"center\" rowspan=\"2\" class=\"tdText\">单位</td>");
            sbr.Append("<td align=\"center\" rowspan=\"2\" class=\"tdText\">投稿数量</td>");

            #region 绑定区局录用情况(只考虑了两级)
            //获取区局录用信息类别名称
            int intLocalCount = 0;//记录区局考核栏目的数量
            List<string> listStrDocClsCd = new List<string>();//用于判断该栏目是否已存在
            foreach (Model.DocCls docClsObject in listDocCls)
            {
                string strDocClsCd = docClsObject.FDocClsCd;
                if (!ztzlDocClsCdList.Contains(strDocClsCd))//如果该信息类别不为专题专栏或其子类
                {
                    if (!listStrDocClsCd.Contains(strDocClsCd))//这个编号不存在
                    {
                        var docClsQuery = from c in listDocCls where c.FPreDocClsCd == strDocClsCd select new { c.FDocClsCd, c.FDocClsName };//判断是否有子级

                        if (docClsQuery.Count() > 0)//有子级的情况下只算子级的内容
                        {
                            foreach (var docCls in docClsQuery)
                            {
                                strLocalDocClsCd += docCls.FDocClsCd + ",";
                                strLocalDocClsName += docCls.FDocClsName + ",";
                                intLocalCount++;
                                listStrDocClsCd.Add(docCls.FDocClsCd);
                            }
                        }
                        else //无子级的情况下只算本级的内容
                        {
                            strLocalDocClsCd += strDocClsCd + ",";
                            strLocalDocClsName += docClsObject.FDocClsName + ",";
                            intLocalCount++;
                            listStrDocClsCd.Add(strDocClsCd);
                        }
                    }
                }
                else//如果是专题专栏或其子类，子类合并在本级下面
                {
                    if (!listStrDocClsCd.Contains(strDocClsCd))//这个编号不存在
                    {
                        if (strDocClsCd == "100")//只添加专题专栏，不添加子类
                        {
                            strLocalDocClsCd += strDocClsCd + ",";
                            strLocalDocClsName += docClsObject.FDocClsName + ",";
                            intLocalCount++;
                            listStrDocClsCd.Add(strDocClsCd);
                        }
                    }
                }
            }

            //绑定区局考核栏目标题行
            if (intLocalCount > 0)
            {
                string strLocalName = ConfigurationManager.AppSettings["doc_order_name"];
                if (string.IsNullOrEmpty(strLocalName))
                {
                    strLocalName = "本级录用情况";
                }
                strLocalDocClsCd = strLocalDocClsCd.Substring(0, strLocalDocClsCd.Length - 1);
                strLocalDocClsName = strLocalDocClsName.Substring(0, strLocalDocClsName.Length - 1);
                sbr.Append("<td align=\"center\" colspan=\"");
                sbr.Append(intLocalCount);
                sbr.Append("\" class=\"tdText\">" + strLocalName + "</td>");
            }
            ViewData["intLocalCount"] = intLocalCount;//把区局列数传到前台，用来做excel导出
            #endregion

            sbr.Append("<td align=\"center\" rowspan=\"2\" class=\"tdText\">录用率</td>");

            #region 绑定上级录用情况(只考虑两级)

            //获取上级录用情况
            string strChkInfoClsCds = string.Empty;//需要计算的上级栏目CD
            string strChkTypes = string.Empty;//需要计算的栏目的计分类型 1按篇计，2手动输入
            string strChkScores = string.Empty;//需要计算的栏目的按篇计分的每篇分数，手动输入的话输入0
            string strChildChkInfoClsNames = string.Empty;//二级栏目的名称


            int intChkCount = 0;//上级录用需要计算的栏目个数

            var chkInfoClsQuery = from c in listChkInfoCls where (null == c.FPreInfoClsNo || c.FPreInfoClsNo == "") && c.FisExamine == "Y" select c;//获取一级栏目（需要考核）

            foreach (Model.ChkInfoCls chkInfoClsObject in chkInfoClsQuery)
            {
                string strChkInfoClsNo = chkInfoClsObject.FInfoClsNo;
                var childChkInfo = from c in listChkInfoCls where c.FPreInfoClsNo == strChkInfoClsNo && c.FisExamine == "Y" select c;
                if (childChkInfo.Count() > 0)//有子节点
                {
                    int t = childChkInfo.Count();//个数
                    //增加主标题列
                    sbr.Append("<td align=\"center\" colspan=\"");
                    sbr.Append(t);
                    sbr.Append("\" class=\"tdText\">");
                    sbr.Append(chkInfoClsObject.FInfoClsName);
                    sbr.Append("录用情况</td>");

                    //获取子集的名称，编号，计分类型，每篇分数
                    foreach (Model.ChkInfoCls model in childChkInfo)
                    {
                        strChkInfoClsCds += model.FInfoClsNo + ",";
                        strChkTypes += model.FChkType + ",";
                        strChkScores += model.FStdScore + ",";
                        strChildChkInfoClsNames += model.FInfoClsName + ",";
                        intChkCount++;
                    }
                }
                else//无子节点 
                {
                    sbr.Append("<td align=\"center\" rowspan=\"2\" class=\"tdText\">");
                    sbr.Append(chkInfoClsObject.FInfoClsName);
                    sbr.Append("</td>");
                    strChkInfoClsCds += chkInfoClsObject.FInfoClsNo + ",";
                    strChkTypes += chkInfoClsObject.FChkType + ",";
                    strChkScores += chkInfoClsObject.FStdScore + ",";
                    intChkCount++;
                }
            }

            if (intChkCount > 0)
            {
                strChkInfoClsCds = strChkInfoClsCds.Trim(',');
                strChkTypes = strChkTypes.Trim(',');
                strChkScores = strChkScores.Trim(',');
                if (strChildChkInfoClsNames != "")
                {
                    strChildChkInfoClsNames = strChildChkInfoClsNames.Trim(',');
                }

                ////增加主标题列
                //sbr.Append("<td align=\"center\" colspan=\"");
                //sbr.Append(intChkCount);
                //sbr.Append("\" class=\"tdText\">");
                //sbr.Append("上级信息录用加分情况</td>");
            }
            ViewData["intChkCount"] = intChkCount;//把上级列数传到前台，用来做excel导出

            #endregion

            sbr.Append("<td align=\"center\" rowspan=\"2\" class=\"tdText\">积分累计</td>");
            sbr.Append("<td align=\"center\" rowspan=\"2\" class=\"tdText\">考核基数</td>");
            sbr.Append("<td align=\"center\" rowspan=\"2\" class=\"tdText\">完成进度</td>");

            sbr.Append("</tr>");

            //第二行
            string[] arrayLocalDocClsName = strLocalDocClsName.Split(',');//需要计算的区局录用信息名称
            string[] arrayStrChildChkInfoClsName = strChildChkInfoClsNames.Split(',');//上级录用二级栏目名称

            sbr.Append("<tr>");

            #region 绑定区局录用子信息类别
            if (intLocalCount > 0)
            {
                foreach (string strDocClsName in arrayLocalDocClsName)
                {
                    sbr.Append("<td align=\"center\" class=\"tdText\">");
                    sbr.Append(strDocClsName);
                    sbr.Append("</td>");
                }
            }
            #endregion

            #region 绑定上级录用子信息类别
            if (strChildChkInfoClsNames != "")
            {
                foreach (string strChkName in arrayStrChildChkInfoClsName)
                {
                    sbr.Append("<td align=\"center\" class=\"tdText\">");
                    sbr.Append(strChkName);
                    sbr.Append("</td>");
                }
            }
            #endregion

            sbr.Append("</tr>");

            #endregion

            #region 绑定数据

            #region 定义全局变量、所用到的参数

            string[] arrayLocalDocClsCd = strLocalDocClsCd.Split(',');//需要计算的区局录用信息编码 
            string[] arrayChkInfoClsCd = strChkInfoClsCds.Split(',');//需要计算的上级栏目CD
            string[] arrayChkType = strChkTypes.Split(',');//需要计算的栏目的计分类型 1按篇计，2手动输入
            string[] arrayChkScore = strChkScores.Split(',');//需要计算的栏目的按篇计分的每篇分数，手动输入的话输入0
            //string[] arrayCheckChkNo = strCheckChkNos.Split('|');//保存所有需要考核的ID字符串，计算上级录用分数的时候，判断栏目编号在数组的哪个字符串中，保存到相应的位置

            int intQjTGSL = 0;//全局投稿数量
            decimal[] decQjTGDF = new decimal[arrayLocalDocClsCd.Length];//保存全局的投稿得分
            decimal[] decQjLocalScore = new decimal[arrayLocalDocClsCd.Length];//保存全局的区局录用情况的每个栏目总分
            decimal[] decQjLocalNum = new decimal[arrayLocalDocClsCd.Length];//保存全局的区局录用情况的每个栏目总篇数
            decimal[] decQjSuperScore = new decimal[arrayChkInfoClsCd.Length];//保存全局的上级录用情况的每个栏目的总分
            //int[] intQjSuperNum = new int[intChkckChkCount_ap];//保存全局的上级录用按篇计的每个栏目的总数量
            decimal decQjSJLYJF = 0;//保存全局的上级录用加分总分
            decimal decQjKHJS = 0;//保存全局的考核基数

            #endregion

            #region 计算合发信息分数（有合发情况，只包括已录用）
            //计算所有合发的信息得分，并添加到list中，在绑定数据时，直接查询统计得分
            Model.DocHfScore docHfScoreModel = new Model.DocHfScore();
            List<Model.DocHfScore> docHfScoreList = new List<Model.DocHfScore>();
            foreach (Model.Document docObj in listDocHF)
            {
                docHfScoreModel = new Model.DocHfScore();
                int intDept = listDeptAll.Where(c => c.FDeptNo == docObj.FDeptNo).Count();
                if (intDept > 0)//这个部门有合发信息时
                {
                    var hfType = from c in listDeptAll where c.FDeptNo == docObj.FDeptNo select c.FUnionScoreType; //定义合发的信息类别
                    var docScoreQuery = from c in listDocClsScore where c.FDocClsCd == docObj.FDocClsCd select c.FEnrollScore;
                    decimal decUnionScore = 0;//此考核栏目的信息考核分定义
                    if (docScoreQuery.Count() > 0)
                    {
                        decUnionScore = docScoreQuery.First();
                    }

                    if (hfType.Count() > 0)
                    {
                        if (hfType.First() == "1")//部门计分方式,1独享，2共享（独享的意思为每个合发部门都获得总分，共享的意思为每个部门只获得平均分）
                        {
                            var dept = from c in documentUnionPubEmplList where c.FDocId == docObj.FDocId && c.FDeptNo != docObj.FDeptNo select c;//所有合发部门,不包括本部门
                            foreach (var obj in dept)//循环合发部门,每个合发部门获得的分数都存入一个docHfScoreModel
                            {
                                docHfScoreModel = new Model.DocHfScore();
                                docHfScoreModel.FDocClsCd = docObj.FDocClsCd;
                                docHfScoreModel.FDeptNo = obj.FDeptNo;
                                docHfScoreModel.FUnionScore = decUnionScore;
                                docHfScoreList.Add(docHfScoreModel);
                            }
                        }
                        else if (hfType.First() == "2")
                        {
                            var dept = from c in documentUnionPubEmplList where c.FDocId == docObj.FDocId && c.FDeptNo != docObj.FDeptNo select c;//所有合发部门,不包括本部门
                            decimal AvgScore = 0;//定义平均分
                            AvgScore = Math.Round(decUnionScore / (dept.Count() + 1), 2);
                            //加上本部门
                            docHfScoreModel = new Model.DocHfScore();
                            docHfScoreModel.FDocClsCd = docObj.FDocClsCd;
                            docHfScoreModel.FDeptNo = docObj.FDeptNo;
                            docHfScoreModel.FUnionScore = AvgScore;

                            docHfScoreList.Add(docHfScoreModel);
                            foreach (var obj in dept)//加上其它部门
                            {
                                docHfScoreModel = new Model.DocHfScore();
                                docHfScoreModel.FDocClsCd = docObj.FDocClsCd;
                                docHfScoreModel.FDeptNo = obj.FDeptNo;
                                docHfScoreModel.FUnionScore = AvgScore;
                                docHfScoreList.Add(docHfScoreModel);
                            }
                        }
                    }
                }
            }
            #endregion

            #region 统计部门合发数量（有合发情况，包括未录用）
            List<Model.DocHfScore> docHfScoreNum = new List<Model.DocHfScore>();//用于统计数量
            foreach (var docObj in listDocHFAll)
            {
                docHfScoreModel = new Model.DocHfScore();
                int intDept = listDeptAll.Where(c => c.FDeptNo == docObj.FDeptNo).Count();
                if (intDept > 0)//这个部门需要计算合发分才进行以下程序
                {
                    var dept = from c in documentUnionPubEmplList where c.FDocId == docObj.FDocId && c.FDeptNo != docObj.FDeptNo select c;//所有合发部门,不包括本部门
                    foreach (var obj in dept)//循环合发部门
                    {
                        docHfScoreModel = new Model.DocHfScore();
                        docHfScoreModel.FDocClsCd = docObj.FDocClsCd;
                        docHfScoreModel.FDeptNo = obj.FDeptNo;

                        //以下添加数量
                        docHfScoreNum.Add(docHfScoreModel);
                    }
                }
            }
            #endregion

            #region 先计算每个部门的进度，真实排序按照部门完成进度来排序

            foreach (Model.HRDept deptObject in listDeptNoVirtual)
            {
                string strDeptNo = deptObject.FDeptNo;
                decimal decLocalDoc = 0;//区局录用情况的总分
                decimal decSuperDoc = 0;//上级录用的分数，用于计算当前单位 上级录用的总分
                decimal intBaseScore = 0;//区局考核基数

                #region 部门区局录用情况

                if (intLocalCount > 0)//有区局录用信息类别
                {
                    //循环需要计算的区局录用考核栏目
                    for (int i = 0; i < arrayLocalDocClsCd.Length; i++)
                    {
                        string strDocClsCd = arrayLocalDocClsCd[i];
                        if (!ztzlDocClsCdList.Contains(strDocClsCd))//如果不是专题专栏及其子类
                        {
                            int intDocCount = 0;//录用的信息条数
                            int intDocCountNoUnion = 0;//未合发的录用信息条数
                            var docQuery = from c in listDoc where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                            if (docQuery.Count() > 0)//如果有录用的信息
                            {
                                intDocCount = docQuery.Count();//录用的篇数
                                decimal decScore = 0;//该类别的录用分数

                                //获取该类别的录用分数
                                var docScoreQuery = from c in listDocClsScore where c.FDocClsCd == strDocClsCd select c.FEnrollScore;
                                if (docScoreQuery.Count() > 0)
                                {
                                    decScore = docScoreQuery.First();
                                }
                                //计算合发的分数
                                decimal decHFScore = 0;
                                //独享（如果是独享的话，就是 未合发分数+合发独享的分数，即不用作任何处理）
                                //共享(如果共享的话，就是 未合发分数+合发平摊到的分数)
                                if (deptObject.FUnionScoreType == "2")
                                {
                                    int docHfCount = listDocHF.Where(c => c.FDeptNo == strDeptNo && c.FDocClsCd == strDocClsCd).ToList().Count();//录用的信息合发条数
                                    //var dochfcount = from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                    intDocCountNoUnion = intDocCount - docHfCount;//获得未合发的信息条数

                                }
                                //获取当前部门、当前考核栏目所得到的合发分数
                                decHFScore = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();


                                decimal sumScore = intDocCountNoUnion * decScore + decHFScore;//未合发数量*单篇分数+合发分数
                                decimal intScore = Math.Round(sumScore * 100, 2) / 100;

                                decLocalDoc += sumScore;//区局录用总分增加

                            }
                            else//如果无录用的信息
                            {
                                //获取合发信息的分数
                                decimal decHFScore = 0;
                                decHFScore = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();
                                decLocalDoc += decHFScore;//区局录用总分增加
                            }
                        }
                        ///////////////////////////专题专栏分隔线/////////////////////////////////////////
                        else//如果是专题专栏或其子类，所有子类分数合并到本级下面
                        {

                            int ztzlDoc = 0;//专题专栏分数
                            foreach (string ztzlstrDocClsCd in ztzlDocClsCdList)
                            {

                                int intDocCount = 0;//录用的信息条数
                                int intDocCountNoUnion = 0;//未合发的录用信息条数
                                var docQuery = from c in listDoc where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                if (docQuery.Count() > 0)//如果有录用的信息
                                {
                                    intDocCount = docQuery.Count();//录用的篇数
                                    decimal decScore = 0;//该类别的录用分数

                                    //获取该类别的录用分数
                                    var docScoreQuery = from c in listDocClsScore where c.FDocClsCd == ztzlstrDocClsCd select c.FEnrollScore;
                                    if (docScoreQuery.Count() > 0)
                                    {
                                        decScore = docScoreQuery.First();
                                    }
                                    //计算合发的分数
                                    decimal decHFScore = 0;
                                    //独享（如果是独享的话，就是 未合发分数+合发独享的分数，即不用作任何处理）
                                    //共享(如果共享的话，就是 未合发分数+合发平摊到的分数)
                                    if (deptObject.FUnionScoreType == "2")
                                    {
                                        int docHfCount = listDocHF.Where(c => c.FDeptNo == strDeptNo && c.FDocClsCd == ztzlstrDocClsCd).ToList().Count();//录用的信息合发条数
                                        //var dochfcount = from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                        intDocCountNoUnion = intDocCount - docHfCount;//获得未合发的信息条数

                                    }
                                    //获取当前部门、当前考核栏目所得到的合发分数
                                    decHFScore = (from c in docHfScoreList where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();


                                    decimal sumScore = intDocCountNoUnion * decScore + decHFScore;//未合发数量*单篇分数+合发分数
                                    decimal intScore = Math.Round(sumScore * 100, 2) / 100;

                                    decLocalDoc += sumScore;//区局录用总分增加
                                }
                                else//如果无录用的信息
                                {
                                    //获取合发信息的分数
                                    decimal decHFScore = 0;
                                    decHFScore = (from c in docHfScoreList where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();
                                    decLocalDoc += decHFScore;//区局录用总分增加
                                }
                            }
                            decLocalDoc += ztzlDoc;
                        }
                    }
                }



                #endregion

                #region 上报信息录用加分情况
                if (intChkCount > 0)//有上级录用情况
                {
                    //循环需要计算的上级录用栏目
                    for (int i = 0; i < arrayChkInfoClsCd.Length; i++)
                    {
                        string strChkInfoClsCd = arrayChkInfoClsCd[i];//栏目编号
                        string strChkType = arrayChkType[i];
                        decimal docSumScore = 0;//总分
                        //慈溪按篇计的代码已经没用了，在后面另有计算代码。
                        if (strChkType == "1")//按篇计
                        {
                            decimal decScore = 0;//每篇的分数

                            int intDocCount = 0;//被录用的信息条数
                            //获取每篇的分数
                            var stdScoreQuery = from c in listChkInfoCls where c.FInfoClsNo == strChkInfoClsCd select c.FStdScore;
                            if (stdScoreQuery.Count() > 0)
                            {
                                decScore = stdScoreQuery.First().Value;
                            }

                            //获取上级录用信息的条数
                            var docCountQuery = from c in chkInfoAuditManual where c.FDeptNo == strDeptNo && c.FInfoClsNo == strChkInfoClsCd select c.FInfoID;

                            if (docCountQuery.Count() > 0)
                            {
                                intDocCount = docCountQuery.Count();
                            }

                            docSumScore = intDocCount * decScore;//该栏目总分                                                   

                        }
                        else if (strChkType == "2")//手动输入
                        {
                            //获取所有的分数
                            var docScoreQuery = from c in chkInfoAuditManual where c.FDeptNo == strDeptNo && c.FInfoClsNo == strChkInfoClsCd && null != c.FScore select c.FScore;
                            if (docScoreQuery.Count() > 0)
                            {
                                foreach (var decscore in docScoreQuery)
                                {
                                    docSumScore += decscore.Value;//该手动录入的分数总分
                                }
                            }
                            int t = 0;

                            if (t == 0)
                            {
                                //decSDLL += docSumScore;//所有手动录入的分数总分
                            }

                        }

                        decimal intSumScore = Math.Round(docSumScore * 100, 2) / 100;

                        decSuperDoc += intSumScore;//增加本部门 上级录用的总分

                    }
                }
                #endregion

                #region 考核基数
                //有区局录用情况则增加区局录用考核

                if (intLocalCount > 0)
                {
                    decimal decBaseScore = 0;
                    //if (decQuarter == 1)
                    //{
                    //    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore1;//获取该部门的考核基数
                    //    if (localBaseScore.Count() > 0)
                    //    {
                    //        decBaseScore = localBaseScore.First();
                    //    }
                    //}
                    //else if (decQuarter == 2)
                    //{
                    //    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore2;//获取该部门的考核基数
                    //    if (localBaseScore.Count() > 0)
                    //    {
                    //        decBaseScore = localBaseScore.First();
                    //    }
                    //}
                    //else if (decQuarter == 3)
                    //{
                    //    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore3;//获取该部门的考核基数
                    //    if (localBaseScore.Count() > 0)
                    //    {
                    //        decBaseScore = localBaseScore.First();
                    //    }
                    //}
                    //else if (decQuarter == 4)
                    //{
                    //    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore4;//获取该部门的考核基数
                    //    if (localBaseScore.Count() > 0)
                    //    {
                    //        decBaseScore = localBaseScore.First();
                    //    }
                    //}
                    //else
                    //{
                    //    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore;//获取该部门的考核基数
                    //    if (localBaseScore.Count() > 0)
                    //    {
                    //        decBaseScore = localBaseScore.First().Value;
                    //    }
                    //}
                    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore;//获取该部门的考核基数
                    if (localBaseScore.Count() > 0)
                    {
                        decBaseScore = localBaseScore.First().Value;
                    }
                    //考核基数
                    intBaseScore = Math.Round(decBaseScore * 100, 2) / 100;
                }
                #endregion

                decimal decWCJD = 0;
                if (intBaseScore != 0)
                {
                    decWCJD = Math.Round((decLocalDoc + decSuperDoc) / intBaseScore * 100, 2);
                }
                else
                {
                    decWCJD = -1;
                }
                deptObject.FDeptSchedule = decWCJD;
            }
            listDeptNoVirtual = (from c in listDeptNoVirtual
                                 orderby c.FIsAgency, c.FDeptSchedule descending, c.FSeq
                                 select c).ToList();
            #endregion

            #region 循环部门，绑定各部门的数字（按照部门完成进度来排序）

            int deptCount = 0;

            foreach (Model.HRDept deptObject in listDeptNoVirtual)
            {
                //增加员工行时，以下1条数据都要置0，或重新实例化
                decimal decLocalDoc = 0;//区局录用情况的总分
                decimal decLocalDocCount = 0;//区局录用情况总数量

                decimal decSuperDoc = 0;//上级录用的分数，用于计算当前单位 上级录用的总分
                decimal decChkInfoSuperSum = 0;//所有按篇计的上级栏目录入的总篇数,用于计算上级录用加分

                sbr.Append("<tr>");

                deptCount++;
                string strDeptNo = deptObject.FDeptNo;
                #region 序号

                string strXH = deptCount.ToString();
                sbr.Append("<td align=\"center\">");
                sbr.Append(strXH);
                sbr.Append("</td>");

                #endregion

                #region 部门名称
                if (type == "ht")
                {
                    sbr.Append("<td align=\"center\">");

                    sbr.Append("<a href=\"" + Url.Content("~/Admin/DocInfoOrder/DocInfoOrderDeptDetail?deptNo="));
                    sbr.Append(strDeptNo);
                    sbr.Append("&year=");
                    sbr.Append(decYear);
                    sbr.Append("&decQuarter=" + decQuarter);
                    sbr.Append("\" >");//target=\"_blank\"
                    sbr.Append(deptObject.FDeptName);
                    sbr.Append("</a>");

                    sbr.Append("</td>");
                }
                else
                {
                    sbr.Append("<td align=\"center\">");

                    sbr.Append(deptObject.FDeptName);

                    sbr.Append("</td>");
                }
                #endregion

                #region 投稿数量

                int deptDocCount = 0;//部门投稿数量
                var deptDoc = from c in listDocAll where c.FDeptNo == strDeptNo select c.FDeptNo;
                if (deptDoc.Count() > 0)
                {
                    deptDocCount = deptDoc.Count();
                }
                int intHfCount = docHfScoreNum.Where(c => c.FDeptNo == strDeptNo).Count();

                intQjTGSL += deptDocCount + intHfCount;//增加全局投稿数量

                sbr.Append("<td align=\"center\">");
                sbr.Append(deptDocCount + intHfCount);//部门投稿数量=部门发布数量+部门合发数量
                sbr.Append("</td>");

                #endregion

                #region 部门区局录用情况

                if (intLocalCount > 0)//有区局录用信息类别
                {
                    //循环需要计算的区局录用考核栏目
                    for (int i = 0; i < arrayLocalDocClsCd.Length; i++)
                    {
                        string strDocClsCd = arrayLocalDocClsCd[i];
                        if (!ztzlDocClsCdList.Contains(strDocClsCd))//如果不是专题专栏及其子类
                        {
                            int intDocCount = 0;//录用的信息条数
                            int intDocCountNoUnion = 0;//未合发的录用信息条数
                            var docQuery = from c in listDoc where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                            if (docQuery.Count() > 0)//如果有录用的信息
                            {
                                intDocCount = docQuery.Count();//录用的篇数
                                decimal decScore = 0;//该类别的录用分数

                                //获取该类别的录用分数
                                var docScoreQuery = from c in listDocClsScore where c.FDocClsCd == strDocClsCd select c.FEnrollScore;
                                if (docScoreQuery.Count() > 0)
                                {
                                    decScore = docScoreQuery.First();
                                }
                                //计算合发的分数
                                decimal decHFScore = 0;
                                //独享（如果是独享的话，就是 未合发分数+合发独享的分数，即不用作任何处理）
                                //共享(如果共享的话，就是 未合发分数+合发平摊到的分数)
                                if (deptObject.FUnionScoreType == "2")
                                {
                                    int docHfCount = listDocHF.Where(c => c.FDeptNo == strDeptNo && c.FDocClsCd == strDocClsCd).ToList().Count();//录用的信息合发条数
                                    //var dochfcount = from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                    intDocCountNoUnion = intDocCount - docHfCount;//获得未合发的信息条数

                                }
                                //获取当前部门、当前考核栏目所得到的合发分数
                                decHFScore = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();


                                decimal sumScore = intDocCountNoUnion * decScore + decHFScore;//未合发数量*单篇分数+合发分数
                                decimal intScore = Math.Round(sumScore * 100, 2) / 100;

                                int intDocHFCount = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c).ToList().Count();//通过其他部门合发的 信息数量
                                sbr.Append("<td align=\"center\">");
                                sbr.Append((intDocCountNoUnion + intDocHFCount).ToString());//数量=发布数量（排除合发的自己发布的信息）+合发数量(包括自己发布的合发信息)
                                sbr.Append("</td>");

                                decLocalDoc += sumScore;//区局录用总分增加
                                decLocalDocCount += (intDocCountNoUnion + intDocHFCount);//区局录用总数量增加
                                decQjLocalScore[i] += sumScore;//增加全局的区局录用情况该子栏目的总分
                                decQjLocalNum[i] += (intDocCountNoUnion + intDocHFCount);//增加全局的区局录用情况该子栏目的总篇数

                            }
                            else//如果无录用的信息
                            {
                                //获取合发信息的分数
                                decimal decHFScore = 0;
                                decHFScore = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();
                                int intDocHFCount = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c).ToList().Count();//通过其他部门合发的 信息数量
                                sbr.Append("<td align=\"center\">" + intDocHFCount.ToString() + "</td>");
                                decLocalDoc += decHFScore;//区局录用总分增加
                                decLocalDocCount += intDocHFCount;//区局录用总数量增加
                                decQjLocalScore[i] += decHFScore;//增加全局的区局录用情况该子栏目的总分
                                //decQjLocalScore[i] += 0;//增加全局的区局录用情况该子栏目的总分
                                decQjLocalNum[i] += intDocHFCount;//增加全局的区局录用情况该子栏目的总篇数
                            }
                        }
                        ///////////////////////////专题专栏分隔线/////////////////////////////////////////
                        else//如果是专题专栏或其子类，所有子类分数合并到本级下面
                        {

                            int ztzlDoc = 0;//专题专栏分数
                            foreach (string ztzlstrDocClsCd in ztzlDocClsCdList)
                            {

                                int intDocCount = 0;//录用的信息条数
                                int intDocCountNoUnion = 0;//未合发的录用信息条数
                                var docQuery = from c in listDoc where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                if (docQuery.Count() > 0)//如果有录用的信息
                                {
                                    intDocCount = docQuery.Count();//录用的篇数
                                    decimal decScore = 0;//该类别的录用分数

                                    //获取该类别的录用分数
                                    var docScoreQuery = from c in listDocClsScore where c.FDocClsCd == ztzlstrDocClsCd select c.FEnrollScore;
                                    if (docScoreQuery.Count() > 0)
                                    {
                                        decScore = docScoreQuery.First();
                                    }
                                    //计算合发的分数
                                    decimal decHFScore = 0;
                                    //独享（如果是独享的话，就是 未合发分数+合发独享的分数，即不用作任何处理）
                                    //共享(如果共享的话，就是 未合发分数+合发平摊到的分数)
                                    if (deptObject.FUnionScoreType == "2")
                                    {
                                        int docHfCount = listDocHF.Where(c => c.FDeptNo == strDeptNo && c.FDocClsCd == ztzlstrDocClsCd).ToList().Count();//录用的信息合发条数
                                        //var dochfcount = from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                        intDocCountNoUnion = intDocCount - docHfCount;//获得未合发的信息条数

                                    }
                                    //获取当前部门、当前考核栏目所得到的合发分数
                                    decHFScore = (from c in docHfScoreList where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();


                                    decimal sumScore = intDocCountNoUnion * decScore + decHFScore;//未合发数量*单篇分数+合发分数
                                    decimal intScore = Math.Round(sumScore * 100, 2) / 100;

                                    int intDocHFCount = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c).ToList().Count();//通过其他部门合发的 信息数量
                                    //sbr.Append("<td align=\"center\">");
                                    //sbr.Append((intDocCountNoUnion + intDocHFCount).ToString());//数量=发布数量（排除合发的自己发布的信息）+合发数量(包括自己发布的合发信息)
                                    //sbr.Append("</td>");
                                    ztzlDoc += intDocCountNoUnion + intDocHFCount;

                                    decLocalDoc += sumScore;//区局录用总分增加
                                    decLocalDocCount += (intDocCountNoUnion + intDocHFCount);//区局录用总数量增加
                                    decQjLocalScore[i] += sumScore;//增加全局的区局录用情况该子栏目的总分
                                    decQjLocalNum[i] += (intDocCountNoUnion + intDocHFCount);//增加全局的区局录用情况该子栏目的总篇数

                                }
                                else//如果无录用的信息
                                {
                                    //获取合发信息的分数
                                    decimal decHFScore = 0;
                                    decHFScore = (from c in docHfScoreList where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();
                                    int intDocHFCount = (from c in docHfScoreList where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c).ToList().Count();//通过其他部门合发的 信息数量
                                    //sbr.Append("<td align=\"center\">" + intDocHFCount.ToString() + "</td>");
                                    ztzlDoc += intDocHFCount;
                                    decLocalDoc += decHFScore;//区局录用总分增加
                                    decLocalDocCount += intDocHFCount;//区局录用总数量增加
                                    decQjLocalScore[i] += decHFScore;//增加全局的区局录用情况该子栏目的总分
                                    //decQjLocalScore[i] += 0;//增加全局的区局录用情况该子栏目的总分
                                    decQjLocalNum[i] += intDocHFCount;//增加全局的区局录用情况该子栏目的总篇数
                                }
                            }

                            sbr.Append("<td align=\"center\">");
                            sbr.Append(ztzlDoc.ToString());
                            sbr.Append("</td>");
                        }
                    }
                }



                #endregion

                #region 录用率
                //录用率=录用考核栏目总数/投稿数量
                decimal decLYL = 0;
                if ((deptDocCount + intHfCount) != 0)
                {
                    decLYL = Math.Round(decLocalDocCount / (deptDocCount + intHfCount) * 100, 2);
                }
                else
                {
                    decLYL = -1;
                }
                string strLYL = "&nbsp;";
                if (decLYL != -1)
                {
                    strLYL = string.Format("{0:F2}", decLYL) + "%";
                }

                sbr.Append("<td align=\"center\">");
                sbr.Append(strLYL);
                sbr.Append("</td>");

                #endregion

                #region 上报信息录用加分情况
                if (intChkCount > 0)//有上级录用情况
                {
                    //循环需要计算的上级录用栏目
                    for (int i = 0; i < arrayChkInfoClsCd.Length; i++)
                    {
                        string strChkInfoClsCd = arrayChkInfoClsCd[i];//栏目编号
                        string strChkType = arrayChkType[i];
                        decimal docSumScore = 0;//总分
                        //慈溪按篇计的代码已经没用了，在后面另有计算代码。
                        if (strChkType == "1")//按篇计
                        {
                            int intDocCount = 0;//被录用的信息条数

                            docSumScore = GetCountByFDocClsCdType1(listChkInfoCls, chkInfoAuditManual, strChkInfoClsCd, strDeptNo, ref intDocCount);//该栏目总分                            
                            decChkInfoSuperSum += intDocCount;//所有按篇计的上级栏目录入的总篇数,用于计算上级录用加分                           

                            //判断该栏目在哪一个考核栏目中
                            //for (int j = 0; j < arrayCheckChkNo.Length; j++)
                            //{
                            //    string strChkInfoNos = arrayCheckChkNo[j];
                            //    string[] arrayExisChkInfoNo = strChkInfoNos.Split(',');
                            //    if (arrayExisChkInfoNo.Contains(strChkInfoClsCd))//如果存在该编号，则相应的考核总数相加
                            //    {
                            //        //arrayDecSuperDoc[j] += docSumScore;
                            //        break;
                            //    }
                            //}

                        }
                        else if (strChkType == "2")//手动输入
                        {
                            //获取所有的分数
                            docSumScore = GetCountByFDocClsCdType2(listChkInfoCls, chkInfoAuditManual, strChkInfoClsCd, strDeptNo);
                            int t = 0;

                            ////判断该栏目在哪一个考核栏目中,如果一级栏目计分是手动录入，则不包含在考核任务中，二级栏目需要判断
                            //for (int j = 0; j < arrayCheckChkNo.Length; j++)
                            //{
                            //    string strChkInfoNos = arrayCheckChkNo[j];
                            //    string[] arrayExisChkInfoNo = strChkInfoNos.Split(',');
                            //    if (arrayExisChkInfoNo.Contains(strChkInfoClsCd))//如果存在该编号，则相应的考核总数相加
                            //    {
                            //        //arrayDecSuperDoc[j] += docSumScore;
                            //        t = 1;
                            //        break;
                            //    }
                            //}

                            if (t == 0)
                            {
                                //decSDLL += docSumScore;//所有手动录入的分数总分
                            }

                        }

                        decimal intSumScore = Math.Round(docSumScore * 100, 2) / 100;

                        sbr.Append("<td align=\"center\">");
                        sbr.Append(string.Format("{0:F2}", intSumScore));
                        sbr.Append("</td>");

                        decSuperDoc += intSumScore;//增加本部门 上级录用的总分
                        decQjSuperScore[i] += intSumScore;//增加全局的上级录用情况的每个栏目总分

                    }
                }
                #endregion

                #region 积分累计(本级+上级)

                sbr.Append("<td align=\"center\">");
                sbr.Append(decLocalDoc + decSuperDoc);
                sbr.Append("</td>");

                #endregion

                #region 考核基数
                decimal intBaseScore = 0;
                //本级
                if (intLocalCount > 0)
                {
                    decimal decBaseScoreLocal = 0;

                    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore;//获取该部门的本级基分
                    if (localBaseScore.Count() > 0)
                    {
                        decBaseScoreLocal = localBaseScore.First().Value;
                    }
                    //考核基数
                    intBaseScore += Math.Round(decBaseScoreLocal * 100, 2) / 100;
                }
                //上级
                if (intChkCount > 0)
                {
                    decimal decBaseScoreSuper = 0;
                    var superBaseScore = from c in listChkInfoStdSuper where c.FDeptNo == strDeptNo select c.FBaseScore;//获取该部门的上级基分
                    if (superBaseScore.Count() > 0)
                    {
                        decBaseScoreSuper = superBaseScore.First().Value;
                    }
                    //考核基数
                    intBaseScore += Math.Round(decBaseScoreSuper * 100, 2) / 100;
                }

                sbr.Append("<td align=\"center\">");
                sbr.Append(intBaseScore);
                sbr.Append("</td>");

                decQjKHJS += intBaseScore;//增加全局考核基数

                #endregion

                #region 完成进度
                decimal decWCJD = 0;
                if (intBaseScore != 0)
                {
                    decWCJD = Math.Round((decLocalDoc + decSuperDoc) / intBaseScore * 100, 2);
                }
                else
                {
                    decWCJD = -1;
                }
                string strWCJD = "&nbsp;";
                if (decWCJD != -1)
                {
                    strWCJD = string.Format("{0:F2}", decWCJD) + "%";
                }
                sbr.Append("<td align=\"center\">");
                sbr.Append(strWCJD);
                sbr.Append("</td>");
                #endregion

                sbr.Append("</tr>");
            }
            #endregion

            #region 合计行
            sbr.Append("<tr>");

            //排序号
            deptCount++;
            sbr.Append("<td align=\"center\">");
            sbr.Append(deptCount.ToString());
            sbr.Append("</td>");

            //单位
            sbr.Append("<td align=\"center\">合计</td>");

            //投稿数量
            sbr.Append("<td align=\"center\">");
            sbr.Append(intQjTGSL.ToString());
            sbr.Append("</td>");

            //本级录用情况
            decimal intQjLocalNumSum = 0;
            if (intLocalCount > 0)
            {
                //循环需要计算的区局录用信息编号
                for (int i = 0; i < arrayLocalDocClsCd.Length; i++)
                {
                    decimal intQjLocalNum = Math.Round(decQjLocalNum[i] * 100, 2) / 100;
                    sbr.Append("<td align=\"center\">");
                    sbr.Append(intQjLocalNum);
                    sbr.Append("</td>");

                    intQjLocalNumSum += intQjLocalNum;//合计全局 本级录用情况分数
                }
            }

            //录用率
            decimal decQjLYL = 0;
            if (intQjTGSL != 0)
            {
                decQjLYL = Math.Round(intQjLocalNumSum / intQjTGSL * 100, 2);
            }
            else
            {
                decQjLYL = -1;
            }
            string strQjLYL = "&nbsp;";
            if (decQjLYL != -1)
            {
                strQjLYL = string.Format("{0:F2}", decQjLYL) + "%";
            }
            sbr.Append("<td align=\"center\">");
            sbr.Append(strQjLYL);
            sbr.Append("</td>");

            //上报信息录用加分情况
            if (intChkCount > 0)
            {
                //循环需要计算的上级录用栏目
                for (int i = 0; i < arrayChkInfoClsCd.Length; i++)
                {
                    sbr.Append("<td align=\"center\">");
                    sbr.Append(string.Format("{0:F2}", decQjSuperScore[i]));
                    sbr.Append("</td>");
                }
            }

            //积分累计
            decimal intQjScoreSum = 0;
            //本级
            if (intLocalCount > 0)
            {
                //循环需要计算的区局录用信息编号
                for (int i = 0; i < arrayLocalDocClsCd.Length; i++)
                {
                    decimal intQjLocalScore = Math.Round(decQjLocalScore[i] * 100, 2) / 100;
                    intQjScoreSum += intQjLocalScore;
                }
            }
            //上级
            if (intChkCount > 0)
            {
                //循环需要计算的上级录用信息
                for (int i = 0; i < arrayChkInfoClsCd.Length; i++)
                {
                    decimal intQjSuperScore = Math.Round(decQjSuperScore[i] * 100, 2) / 100;
                    intQjScoreSum += intQjSuperScore;
                }
            }
            sbr.Append("<td align=\"center\">");
            sbr.Append(intQjScoreSum.ToString());
            sbr.Append("</td>");

            //考核基数
            sbr.Append("<td align=\"center\">");
            sbr.Append(decQjKHJS.ToString());
            sbr.Append("</td>");

            //完成进度
            decimal decQjWCJD = 0;
            if (decQjKHJS != 0)
            {
                decQjWCJD = Math.Round(intQjScoreSum / decQjKHJS * 100, 2);
            }
            else
            {
                decQjWCJD = -1;
            }
            string strQjWCJD = "&nbsp;";
            if (decQjWCJD != -1)
            {
                strQjWCJD = string.Format("{0:F2}", decQjWCJD) + "%";
            }
            sbr.Append("<td align=\"center\">");
            sbr.Append(strQjWCJD);
            sbr.Append("</td>");

            sbr.Append("</tr>");
            #endregion

            #endregion



            return sbr.ToString();
        }

        //产生当前部门信息明细
        private List<string> CreateDocInfoDeptDetail(string strEntityNo, decimal decQuarter, string strDeptNo, decimal decYear)
        {
            BLL.Document docBll = new BLL.Document();
            BLL.DocClsScore docClsScoreBll = new BLL.DocClsScore();
            BLL.HRDept deptBll = new BLL.HRDept();
            BLL.ChkInfoCls chkInfoClsBll = new BLL.ChkInfoCls();
            BLL.ChkInfoAuditManual chkInfoAuditManualBll = new BLL.ChkInfoAuditManual();
            BLL.DocumentUnionPubEmpl documentUnionPubEmplBll = new BLL.DocumentUnionPubEmpl();
            BLL.HREmpl EmplBll = new BLL.HREmpl();

            string strQuarter = GetStrQuarter(decYear, decQuarter);



            //临时
            List<Model.Document> listDoc = new List<Model.Document>();
            if (strDeptNo != "218")
            {
                listDoc = docBll.getDocByChkInfoAuditEntryByDept(strEntityNo, decYear, strDeptNo, strQuarter.Replace("FPubDate", "FDisplayDate"));//获取某个部门的所有需要考核的信息(已录用,未删除)
            }
            else
            {
                listDoc = docBll.getDocByChkInfoAuditEntryByDept(strEntityNo, decYear, strDeptNo, strQuarter.Replace("FPubDate", "FDisplayDate"));//获取某个部门的所有需要考核的信息(已录用,未删除)

                List<Model.Document> listDoc1 = docBll.getDocByChkInfoAuditEntryByDept(strEntityNo, decYear, "213", strQuarter.Replace("FPubDate", "FDisplayDate"));//获取某个部门的所有需要考核的信息(已录用,未删除)

                listDoc.AddRange(listDoc1);

                listDoc = (from c in listDoc
                           orderby c.FPubDate
                           select c).ToList();
            }
            //List<Model.Document> listDoc = docBll.getDocByChkInfoAuditEntryByDept(strEntityNo, decYear, strDeptNo, strQuarter.Replace("FPubDate", "FDisplayDate"));//获取某个部门的所有需要考核的信息(已录用,未删除)





            List<Model.DocClsScore> listDocClsScore = docClsScoreBll.getListByYearAndIsScore(strEntityNo, decYear);//获得区级考核信息栏目考核分定义
            List<Model.HRDept> listDept = deptBll.GetDeptListAll(strEntityNo);
            List<Model.ChkInfoCls> listChkInfoCls = chkInfoClsBll.GetListByYear(strEntityNo, decYear);//获得上级录用栏目信息
            List<Model.ChkInfoAuditManual> listchkInfoAuditManual = chkInfoAuditManualBll.GetListByYearAndDeptNo(strEntityNo, strDeptNo, decYear, strQuarter.Replace("FPubDate", "FAuditDate"));//获得上级录用信息明细

            List<Model.DocumentUnionPubEmpl> documentUnionPubEmplList = documentUnionPubEmplBll.GetModelList_DocIdAndDeptNo("");

            List<string> strList = new List<string>();
            System.Text.StringBuilder sbr = new System.Text.StringBuilder();
            string strPreChkInfoNo = string.Empty;//保存一级上级录用栏目编号

            int intPreChkInfoNo = 0;//保存一级上级录用栏目编号的个数



            //string viewUrl = ""System.Configuration.ConfigurationManager.AppSettings["docViewUrl"];
            //if (string.IsNullOrEmpty(viewUrl))
            //{
                
            //}
            string viewUrl ="/Index/docView?docId=";
            if (listDoc.Count() > 0)
            {
                sbr.Append("<Label ID=\"lbBase\" CssClass=\"lbClass\" style=\"font-size:20px\">区本级录用信息</Label>");
            }
            sbr.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"table\" >");

            //绑定标题行
            sbr.Append("<tr>");
            sbr.Append("<td align=\"center\" class=\"tdText\">序号</td>");
            sbr.Append("<td align=\"center\" class=\"tdText\">信息标题</td>");
            sbr.Append("<td align=\"center\" class=\"tdText\">信息类别</td>");
            sbr.Append("<td align=\"center\" class=\"tdText\">发布人</td>");
            sbr.Append("<td align=\"center\" class=\"tdText\">投稿日期</td>");
            //if (listDocClsScore.Count > 0)//已定义区级考核分栏目
            //{
            //    sbr.Append("<td align=\"center\" class=\"tdText\">录用基本分</td>");
            //}
            var chkInfoClsQuery = from c in listChkInfoCls where (null == c.FPreInfoClsNo || c.FPreInfoClsNo == "") select c;//获取一级栏目

            if (intPreChkInfoNo > 0)
            {
                strPreChkInfoNo = strPreChkInfoNo.Substring(0, strPreChkInfoNo.Length - 1);
            }

            string[] arrayStrPreCHkInfoNo = strPreChkInfoNo.Split(',');//上级录用一级栏目编号数组

            sbr.Append("<td align=\"center\" class=\"tdText\">得分合计</td>");
            sbr.Append("</tr>");

            //绑定数据
            int intDocCount = 0;//信息条数
            foreach (Model.Document docObject in listDoc)
            {
                intDocCount++;
                decimal decSum = 0;//录用总分
                decimal decScore = 0;//录取分数
                string strDocClsCd = docObject.FDocClsCd;
                decimal decDocId = docObject.FDocId;
                sbr.Append("<tr>");


                sbr.Append("<td align=\"center\" >");
                sbr.Append(intDocCount);
                sbr.Append("</td>");

                sbr.Append("<td align=\"center\" >");
                sbr.Append("<a href=\"");
                sbr.Append(viewUrl);
                sbr.Append(docObject.FDocId);
                sbr.Append(" \" target=\"_blank\">");
                sbr.Append(docObject.FTitle);
                sbr.Append("</a>");
                sbr.Append("</td>");

                sbr.Append("<td align=\"center\" >");
                sbr.Append(docObject.FDocClsName);
                sbr.Append("</td>");

                sbr.Append("<td align=\"center\" >");
                sbr.Append(docObject.FEmpName);
                sbr.Append("</td>");

                sbr.Append("<td align=\"center\" >");
                sbr.Append(docObject.FPubDate.ToString("yyyy-MM-dd"));
                sbr.Append("</td>");

                if (listDocClsScore.Count > 0)//已定义区级考核分栏目
                {

                    var scoreQuery = from c in listDocClsScore where c.FDocClsCd == strDocClsCd select c.FEnrollScore;//获取该类别的录取分数
                    if (scoreQuery.Count() > 0)
                    {
                        decScore = scoreQuery.First();
                    }
                    //先进行合发信息判断，再进行计算
                    var hfType = from c in listDept where c.FDeptNo == docObject.FDeptNo select c.FUnionScoreType; //定义合发的信息类别
                    if (hfType.Count() > 0)
                    {
                        if (hfType.First() == "2")
                        {
                            var dept = from c in documentUnionPubEmplList where c.FDocId == docObject.FDocId && c.FDeptNo != docObject.FDeptNo select c;//所有合发部门,不包括本部门
                            if (dept.Count() > 0)
                            {
                                decScore = Math.Round((decScore / (dept.Count() + 1)) * 100, 2) / 100;
                            }
                        }
                    }
                }

                ////录用分数
                //sbr.Append("<td align=\"center\" >");
                //sbr.Append(decScore);
                //sbr.Append("</td>");

                decSum = Math.Round(decScore*100, 2)/100;

                //得分合计
                sbr.Append("<td align=\"center\" >");
                sbr.Append(string.Format("{0:F2}",decSum));
                sbr.Append("</td>");


                sbr.Append("</tr>");

            }
            sbr.Append("</table>");

            strList.Add(sbr.ToString());


            #region 上级录用信息
            sbr = new System.Text.StringBuilder();
            if (listchkInfoAuditManual.Count > 0)
            {
                sbr.Append("<Label ID=\"lbChkInfo\" CssClass=\"lbClass\" style=\"font-size:20px\">上级录用信息</Label>");
                sbr.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"table\" >");

                //绑定标题行
                sbr.Append("<tr>");
                sbr.Append("<td align=\"center\" class=\"tdText\">序号</td>");
                sbr.Append("<td align=\"center\" class=\"tdText\">信息标题</td>");
                sbr.Append("<td align=\"center\" class=\"tdText\">作者</td>");
                sbr.Append("<td align=\"center\" class=\"tdText\">发布日期</td>");
                sbr.Append("<td align=\"center\" class=\"tdText\">上级录用栏目</td>");
                sbr.Append("<td align=\"center\" class=\"tdText\">刊登媒体</td>");
                sbr.Append("<td align=\"center\" class=\"tdText\">版面</td>");
                sbr.Append("<td align=\"center\" class=\"tdText\">录用得分</td>");

                sbr.Append("</tr>");

                //绑定数据
                intDocCount = 0;//信息条数
                foreach (Model.ChkInfoAuditManual chkObj in listchkInfoAuditManual)
                {
                    intDocCount++;
                    decimal decSum = 0;//录用总分

                    string strDocClsCd = chkObj.FInfoClsNo;
                    decimal decInfoID = chkObj.FInfoID;
                    sbr.Append("<tr>");

                    sbr.Append("<td align=\"center\" >");
                    sbr.Append(intDocCount);
                    sbr.Append("</td>");

                    sbr.Append("<td align=\"center\" >");
                    sbr.Append(chkObj.FTitle);
                    sbr.Append("</td>");

                    string TempName = string.Empty;
                    if (!string.IsNullOrEmpty(chkObj.FEmpNo))
                    {
                        TempName = EmplBll.GetEmpName(strEntityNo, chkObj.FEmpNo);
                    }
                    else
                    {
                        TempName = deptBll.GetDeptName(strEntityNo, chkObj.FDeptNo);
                    }
                    sbr.Append("<td align=\"center\" >");
                    sbr.Append(TempName);
                    sbr.Append("</td>");

                    sbr.Append("<td align=\"center\" >");
                    sbr.Append(chkObj.FAuditDate.Value.ToString("yyyy-MM-dd"));
                    sbr.Append("</td>");

                    var fInfoClsName = from c in listChkInfoCls where c.FInfoClsNo == strDocClsCd select c.FInfoClsName;
                    sbr.Append("<td align=\"center\" >");
                    sbr.Append(fInfoClsName.First());
                    sbr.Append("</td>");

                    sbr.Append("<td align=\"center\" >");
                    sbr.Append(chkObj.FInfoMedia);
                    sbr.Append("&nbsp;</td>");

                    sbr.Append("<td align=\"center\" >");
                    sbr.Append(chkObj.FPage);//版面
                    sbr.Append("&nbsp;</td>");

                    var fChkType = from c in listChkInfoCls where c.FInfoClsNo == strDocClsCd select c.FChkType;
                    if (fChkType.First() == "1")
                    {
                        var fStdScore = from c in listChkInfoCls where c.FInfoClsNo == strDocClsCd select c.FStdScore;
                        sbr.Append("<td align=\"center\" >");
                        sbr.Append(fStdScore.First());
                        sbr.Append("</td>");
                    }
                    else
                    {
                        sbr.Append("<td align=\"center\" >");
                        sbr.Append(chkObj.FScore);
                        sbr.Append("</td>");
                    }

                    sbr.Append("</tr>");
                }
                sbr.Append("</table>");

            }
            if (sbr.ToString() != "")
            {
                strList.Add(sbr.ToString());
            }
            else
            {
                strList.Add("");
            }
            #endregion



            return strList;
        }


        //生成录用季度Where语句strQuarter
        private string GetStrQuarter(decimal decYear, decimal decQuarter)
        {
            decimal tempyear = decYear + 1;
            string strQuarter = " FPubDate between '" + decYear + "' and '" + tempyear + "' ";//按日期查询的sql语句
            //decQuarter=0,为全年，1，2，3，4分别对应四个季度
            if (decQuarter == 1)
            {
                strQuarter = decYear.ToString() + "-01-01";
                strQuarter = " datediff(quarter,FPubDate,'" + strQuarter + "')=0 ";
            }
            else if (decQuarter == 2)
            {
                strQuarter = decYear.ToString() + "-04-01";
                strQuarter = " datediff(quarter,FPubDate,'" + strQuarter + "')=0 ";
            }
            else if (decQuarter == 3)
            {
                strQuarter = decYear.ToString() + "-07-01";
                strQuarter = " datediff(quarter,FPubDate,'" + strQuarter + "')=0 ";
            }
            else if (decQuarter == 4)
            {
                strQuarter = decYear.ToString() + "-10-01";
                strQuarter = " datediff(quarter,FPubDate,'" + strQuarter + "')=0 ";
            }
            return strQuarter;
        }

        //生成投稿数量季度Where语句strQuarter
        private string GetStrQuarterOther(decimal decYear, decimal decQuarter)
        {
            decimal tempyear = decYear - 1;
            string strQuarter = " FPubDate between '" + tempyear + "-12-26" + "' and '" + decYear + "-12-25" + "' ";//按日期查询的sql语句
            //decQuarter=0,为全年，1，2，3，4分别对应四个季度
            if (decQuarter == 1)
            {
                strQuarter = tempyear.ToString();
                strQuarter = " datediff(day,FPubDate,'" + strQuarter + "-12-26" + "')<=0 and datediff(day,FPubDate,'" + (decimal.Parse(strQuarter) + 1).ToString() + "-03-31" + "')>=0";
            }
            else if (decQuarter == 2)
            {
                strQuarter = decYear.ToString();
                strQuarter = " datediff(day,FPubDate,'" + strQuarter + "-03-31" + "')<=0 and datediff(day,FPubDate,'" + strQuarter + "-06-30" + "')>=0 ";
            }
            else if (decQuarter == 3)
            {
                strQuarter = decYear.ToString();
                strQuarter = " datediff(day,FPubDate,'" + strQuarter + "-07-01" + "')<=0 and datediff(day,FPubDate,'" + strQuarter + "-09-30" + "')>=0";
            }
            else if (decQuarter == 4)
            {
                strQuarter = decYear.ToString();
                strQuarter = " datediff(day,FPubDate,'" + strQuarter + "-10-01" + "')<=0 and datediff(day,FPubDate,'" + strQuarter + "-12-25" + "')>=0";
            }
            return strQuarter;
        }
        #region 导出Excel
        //导出excel
        public ActionResult ExportToExcel()
        {
            string year = "";
            string quarter = "";
            if (Fetch.Post("hidFYear") != "")
            {
                year = Fetch.Post("hidFYear");
            }
            if (Fetch.Post("hidFQuarter") != "")
            {
                quarter = Fetch.Post("hidFQuarter");
            }
            int intLocalCount = int.Parse(Fetch.Post("hidIntLocalCount"));//区局考核栏目列数
            int intChkCount = int.Parse(Fetch.Post("hidIntChkCount"));//上级录用栏目列数
            return File(CreateXLS(year, quarter, intLocalCount, intChkCount), "application/vnd.ms-excel", "信息排行榜.xls");
        }

        private Byte[] CreateXLS(string year,string quarter,int intLocalCount,int intChkCount)
        {
            List<Model.XlsModel> xlsModels = new List<Model.XlsModel>();

            Model.XlsModel xlsModel = new Model.XlsModel();

            List<Model.XlsModel> xlsModels1 = createXlsTable(year,quarter);
            xlsModels.AddRange(xlsModels1);

            List<Model.XlsModel_Column> xlsModelColumns = new List<Model.XlsModel_Column>();
            //计算最后列的编号
            int intColumnCount = 7 + intLocalCount + intChkCount-1;

            Model.XlsModel_Column xmc = new Model.XlsModel_Column(); xmc.ColumnIndexEnd = (ushort)intColumnCount; xmc.ColumnIndexStart = 0; xmc.Width = 11; xlsModelColumns.Add(xmc);
            return GenerateUtil.ExportToExcelReturnPath1(".cls", "信息排行榜", xlsModels1.Count + 1, xlsModels, xlsModelColumns, new List<Model.XlsModel_Row>());
        }

        private List<Model.XlsModel> createXlsTable(string year, string quarter)
        {
            List<Model.XlsModel> xlsModels = new List<Model.XlsModel>();
            Model.XlsModel xm = new Model.XlsModel();

            //单位编号
            string strEntityNo = ConfigurationManager.AppSettings["EntityNo"].ToString();
            decimal decYear = decimal.Parse(year);
            decimal decQuarter = decimal.Parse(quarter);
            string strQuarter = GetStrQuarter(decYear, decQuarter);//生成录用数量季度Where语句strQuarter
            string strQuarterOther = GetStrQuarterOther(decYear, decQuarter);//生成投稿数量季度Where语句strQuarter
            #region 需要用到的数据
            BLL.Document docBll = new BLL.Document();
            BLL.DocCls docClsBll = new BLL.DocCls();
            BLL.DocClsScore docClsScoreBll = new BLL.DocClsScore();
            BLL.ChkInfoCls chkInfoClsBll = new BLL.ChkInfoCls();
            BLL.HRDept deptBll = new BLL.HRDept();
            BLL.DocumentUnionPubEmpl docUnionPubEmplBll = new BLL.DocumentUnionPubEmpl();
            BLL.ChkInfoAuditManual chkInfoAuditManualBll = new BLL.ChkInfoAuditManual();
            BLL.ChkInfoStdLocal chkInfoStdLocalBll = new BLL.ChkInfoStdLocal();
            BLL.ChkInfoStdSuper chkInfoStdSuperBll = new BLL.ChkInfoStdSuper();

            List<Model.Document> listDoc = docBll.getDocByScore(strEntityNo, decYear, strQuarter.Replace("FPubDate", "FDisplayDate"));//获得所有需要考核的信息(已录用，未删除，信息考核分已定义)
            List<Model.Document> listDocAll = docBll.getDocByScoreAll(strEntityNo, decYear, strQuarterOther);//获得所有需要考核的信息(包括未录用),主要用于统计投稿数量

            List<Model.DocCls> listDocCls = docClsBll.getDocClsByScore(strEntityNo, decYear);//获得区级考核信息栏目(信息考核分定义里有定义过的。)
            List<Model.DocClsScore> listDocClsScore = docClsScoreBll.getListByYearAndIsScore(strEntityNo, decYear);//获得区级考核信息栏目考核分定义

            List<Model.ChkInfoCls> listChkInfoCls = chkInfoClsBll.GetListByYear(strEntityNo, decYear);//获得上级录用栏目信息
            List<Model.ChkInfoAuditManual> chkInfoAuditManual = chkInfoAuditManualBll.GetListByYear(strEntityNo, decYear, "");//获得上级录用信息明细
            List<Model.ChkInfoStdLocal> listChkInfoStdLocal = chkInfoStdLocalBll.GetListByYear2(strEntityNo, decYear);//获取所有区本级录用的基分和部门编号
            List<Model.ChkInfoStdSuper> listChkInfoStdSuper = chkInfoStdSuperBll.GetListByYear2(strEntityNo, decYear);//获取上级录用的基分和部门编号

            List<Model.HRDept> listDeptAll = deptBll.GetDeptListAll(strEntityNo);//获取所有部门信息（包括虚拟部门）
            List<Model.HRDept> listDeptNoVirtual = deptBll.getDeptListNoVirtual(strEntityNo, decYear);//获取部门信息,不包括虚拟部门

            List<Model.Document> listDocHF = docBll.GetDocByHF(strEntityNo, strQuarter.Replace("FPubDate", "FDisplayDate"));//获取有合发情况的信息(已录用，未删除)
            List<Model.Document> listDocHFAll = docBll.GetDocByHFAll(strEntityNo, strQuarterOther);//获取有合发情况的信息(包括未录用，未删除)
            List<Model.DocumentUnionPubEmpl> documentUnionPubEmplList = docUnionPubEmplBll.GetModelList_DocIdAndDeptNo("");//合发数据根据FDocId,FDeptNo分组，用于查询某文档的所有部门编号

            string strLocalDocClsCd = string.Empty;//需要计算的区局录用信息类别编号
            string strLocalDocClsName = string.Empty;//需要计算的区局录用信息类别名称

            //获取专题专栏及其子类栏目的编号
            List<string> ztzlDocClsCdList = (from c in listDocCls
                                             where c.FDocClsCd == "100" || c.FPreDocClsCd == "100"
                                             select c.FDocClsCd).ToList();








            //临时
            listDeptNoVirtual = (from c in listDeptNoVirtual
                                 where c.FDeptNo != "213"
                                 select c).ToList();

            foreach (Model.Document model in listDoc)
            {
                if (model.FDeptNo == "213")
                {
                    model.FDeptNo = "218";
                }
            }

            foreach (Model.Document model in listDocAll)
            {
                if (model.FDeptNo == "213")
                {
                    model.FDeptNo = "218";
                }
            }





            #endregion

            #region 绑定标题行
            int rowIndex = 1;
            //第一行
            xm = new Model.XlsModel();
            xm.Title = "排序";
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xm.RowSpan = 2;
            xlsModels.Add(xm);

            xm = new Model.XlsModel();
            xm.Title = "单位";
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xm.RowSpan = 2;
            xlsModels.Add(xm);

            xm = new Model.XlsModel();
            xm.Title = "投稿数量";
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xm.RowSpan = 2;
            xlsModels.Add(xm);

            #region 绑定区局录用情况(只考虑了两级)
            //获取区局录用信息类别名称
            int intLocalCount = 0;//记录区局考核栏目的数量
            List<string> listStrDocClsCd = new List<string>();//用于判断该栏目是否已存在
            foreach (Model.DocCls docClsObject in listDocCls)
            {
                string strDocClsCd = docClsObject.FDocClsCd;
                if (!ztzlDocClsCdList.Contains(strDocClsCd))//如果该信息类别不为专题专栏或其子类
                {
                    if (!listStrDocClsCd.Contains(strDocClsCd))//这个编号不存在
                    {
                        var docClsQuery = from c in listDocCls where c.FPreDocClsCd == strDocClsCd select new { c.FDocClsCd, c.FDocClsName };//判断是否有子级

                        if (docClsQuery.Count() > 0)//有子级的情况下只算子级的内容
                        {
                            foreach (var docCls in docClsQuery)
                            {
                                strLocalDocClsCd += docCls.FDocClsCd + ",";
                                strLocalDocClsName += docCls.FDocClsName + ",";
                                intLocalCount++;
                                listStrDocClsCd.Add(docCls.FDocClsCd);
                            }
                        }
                        else //无子级的情况下只算本级的内容
                        {
                            strLocalDocClsCd += strDocClsCd + ",";
                            strLocalDocClsName += docClsObject.FDocClsName + ",";
                            intLocalCount++;
                            listStrDocClsCd.Add(strDocClsCd);
                        }
                    }
                }
                else//如果是专题专栏或其子类，子类合并在本级下面
                {
                    if (!listStrDocClsCd.Contains(strDocClsCd))//这个编号不存在
                    {
                        if (strDocClsCd == "100")//只添加专题专栏，不添加子类
                        {
                            strLocalDocClsCd += strDocClsCd + ",";
                            strLocalDocClsName += docClsObject.FDocClsName + ",";
                            intLocalCount++;
                            listStrDocClsCd.Add(strDocClsCd);
                        }
                    }
                }
            }

            //绑定区局考核栏目标题行
            if (intLocalCount > 0)
            {
                string strLocalName = ConfigurationManager.AppSettings["doc_order_name"];
                if (string.IsNullOrEmpty(strLocalName))
                {
                    strLocalName = "本级录用情况";
                }
                strLocalDocClsCd = strLocalDocClsCd.Substring(0, strLocalDocClsCd.Length - 1);
                strLocalDocClsName = strLocalDocClsName.Substring(0, strLocalDocClsName.Length - 1);

                xm = new Model.XlsModel();
                xm.Title = strLocalName;
                xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xm.RowIndex = rowIndex;
                xm.ColSpan = intLocalCount;
                xlsModels.Add(xm);
            }
            ViewData["intLocalCount"] = intLocalCount;//把区局列数传到前台，用来做excel导出
            #endregion

            xm = new Model.XlsModel();
            xm.Title = "录用率";
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xm.RowSpan = 2;
            xlsModels.Add(xm);

            #region 绑定上级录用情况(只考虑两级)

            //获取上级录用情况
            string strChkInfoClsCds = string.Empty;//需要计算的上级栏目CD
            string strChkTypes = string.Empty;//需要计算的栏目的计分类型 1按篇计，2手动输入
            string strChkScores = string.Empty;//需要计算的栏目的按篇计分的每篇分数，手动输入的话输入0
            string strChildChkInfoClsNames = string.Empty;//二级栏目的名称


            int intChkCount = 0;//上级录用需要计算的栏目个数

            var chkInfoClsQuery = from c in listChkInfoCls where (null == c.FPreInfoClsNo || c.FPreInfoClsNo == "") && c.FisExamine == "Y" select c;//获取一级栏目（按分计分 或者 需要考核）

            foreach (Model.ChkInfoCls chkInfoClsObject in chkInfoClsQuery)
            {
                string strChkInfoClsNo = chkInfoClsObject.FInfoClsNo;
                var childChkInfo = from c in listChkInfoCls where c.FPreInfoClsNo == strChkInfoClsNo && c.FisExamine == "Y" select c;
                if (childChkInfo.Count() > 0)//有子节点
                {
                    int t = childChkInfo.Count();//个数
                    //增加主标题列
                    xm = new Model.XlsModel();
                    xm.Title = chkInfoClsObject.FInfoClsName;
                    xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                    xm.RowIndex = rowIndex;
                    xm.ColSpan = t;
                    xlsModels.Add(xm);

                    //获取子集的名称，编号，计分类型，每篇分数
                    foreach (Model.ChkInfoCls model in childChkInfo)
                    {
                        strChkInfoClsCds += model.FInfoClsNo + ",";
                        strChkTypes += model.FChkType + ",";
                        strChkScores += model.FStdScore + ",";
                        strChildChkInfoClsNames += model.FInfoClsName + ",";
                        intChkCount++;
                    }
                }
                else//无子节点 
                {
                    xm = new Model.XlsModel();
                    xm.Title = chkInfoClsObject.FInfoClsName;
                    xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                    xm.RowIndex = rowIndex;
                    xm.RowSpan = 2;
                    xlsModels.Add(xm);

                    strChkInfoClsCds += chkInfoClsObject.FInfoClsNo + ",";
                    strChkTypes += chkInfoClsObject.FChkType + ",";
                    strChkScores += chkInfoClsObject.FStdScore + ",";
                    intChkCount++;
                }
            }

            if (intChkCount > 0)
            {
                strChkInfoClsCds = strChkInfoClsCds.Trim(',');
                strChkTypes = strChkTypes.Trim(',');
                strChkScores = strChkScores.Trim(',');
                if (strChildChkInfoClsNames != "")
                {
                    strChildChkInfoClsNames = strChildChkInfoClsNames.Trim(',');
                }

                ////增加主标题列
                //xm = new Model.XlsModel();
                //xm.Title = "上级信息录用加分情况";
                //xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                //xm.RowIndex = rowIndex;
                //xm.ColSpan = intChkCount;
                //xlsModels.Add(xm);

            }
            ViewData["intChkCount"] = intChkCount;//把上级列数传到前台，用来做excel导出

            #endregion

            xm = new Model.XlsModel();
            xm.Title = "积分累计";
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xm.RowSpan = 2;
            xlsModels.Add(xm);

            xm = new Model.XlsModel();
            xm.Title = "考核基数";
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xm.RowSpan = 2;
            xlsModels.Add(xm);

            xm = new Model.XlsModel();
            xm.Title = "完成进度";
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xm.RowSpan = 2;
            xlsModels.Add(xm);

            //第二行
            rowIndex++;
            string[] arrayLocalDocClsName = strLocalDocClsName.Split(',');//需要计算的区局录用信息名称
            string[] arrayStrChildChkInfoClsName = strChildChkInfoClsNames.Split(',');//上级录用二级栏目名称

            #region 绑定区局录用子信息类别
            if (intLocalCount > 0)
            {
                foreach (string strDocClsName in arrayLocalDocClsName)
                {
                    xm = new Model.XlsModel();
                    xm.Title = strDocClsName;
                    xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                    xm.RowIndex = rowIndex;
                    xlsModels.Add(xm);
                }
            }
            #endregion

            #region 绑定上级录用子信息类别
            if (strChildChkInfoClsNames != "")
            {
                foreach (string strChkName in arrayStrChildChkInfoClsName)
                {
                    xm = new Model.XlsModel();
                    xm.Title = strChkName;
                    xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                    xm.RowIndex = rowIndex;
                    xlsModels.Add(xm);
                }
            }
            #endregion

            #endregion

            #region 绑定数据

            #region 定义全局变量、所用到的参数

            string[] arrayLocalDocClsCd = strLocalDocClsCd.Split(',');//需要计算的区局录用信息编码 
            string[] arrayChkInfoClsCd = strChkInfoClsCds.Split(',');//需要计算的上级栏目CD
            string[] arrayChkType = strChkTypes.Split(',');//需要计算的栏目的计分类型 1按篇计，2手动输入
            string[] arrayChkScore = strChkScores.Split(',');//需要计算的栏目的按篇计分的每篇分数，手动输入的话输入0
            //string[] arrayCheckChkNo = strCheckChkNos.Split('|');//保存所有需要考核的ID字符串，计算上级录用分数的时候，判断栏目编号在数组的哪个字符串中，保存到相应的位置

            int intQjTGSL = 0;//全局投稿数量
            decimal[] decQjTGDF = new decimal[arrayLocalDocClsCd.Length];//保存全局的投稿得分
            decimal[] decQjLocalScore = new decimal[arrayLocalDocClsCd.Length];//保存全局的区局录用情况的每个栏目总分
            decimal[] decQjLocalNum = new decimal[arrayLocalDocClsCd.Length];//保存全局的区局录用情况的每个栏目总篇数
            decimal[] decQjSuperScore = new decimal[arrayChkInfoClsCd.Length];//保存全局的上级录用情况的每个栏目的总分
            //int[] intQjSuperNum = new int[intChkckChkCount_ap];//保存全局的上级录用按篇计的每个栏目的总数量
            decimal decQjSJLYJF = 0;//保存全局的上级录用加分总分
            decimal decQjKHJS = 0;//保存全局的考核基数

            #endregion

            #region 计算合发信息分数（有合发情况，只包括已录用）
            //计算所有合发的信息得分，并添加到list中，在绑定数据时，直接查询统计得分
            Model.DocHfScore docHfScoreModel = new Model.DocHfScore();
            List<Model.DocHfScore> docHfScoreList = new List<Model.DocHfScore>();
            foreach (Model.Document docObj in listDocHF)
            {
                docHfScoreModel = new Model.DocHfScore();
                int intDept = listDeptAll.Where(c => c.FDeptNo == docObj.FDeptNo).Count();
                if (intDept > 0)//这个部门有合发信息时
                {
                    var hfType = from c in listDeptAll where c.FDeptNo == docObj.FDeptNo select c.FUnionScoreType; //定义合发的信息类别
                    var docScoreQuery = from c in listDocClsScore where c.FDocClsCd == docObj.FDocClsCd select c.FEnrollScore;
                    decimal decUnionScore = 0;//此考核栏目的信息考核分定义
                    if (docScoreQuery.Count() > 0)
                    {
                        decUnionScore = docScoreQuery.First();
                    }

                    if (hfType.Count() > 0)
                    {
                        if (hfType.First() == "1")//部门计分方式,1独享，2共享（独享的意思为每个合发部门都获得总分，共享的意思为每个部门只获得平均分）
                        {
                            var dept = from c in documentUnionPubEmplList where c.FDocId == docObj.FDocId && c.FDeptNo != docObj.FDeptNo select c;//所有合发部门,不包括本部门
                            foreach (var obj in dept)//循环合发部门,每个合发部门获得的分数都存入一个docHfScoreModel
                            {
                                docHfScoreModel = new Model.DocHfScore();
                                docHfScoreModel.FDocClsCd = docObj.FDocClsCd;
                                docHfScoreModel.FDeptNo = obj.FDeptNo;
                                docHfScoreModel.FUnionScore = decUnionScore;
                                docHfScoreList.Add(docHfScoreModel);
                            }
                        }
                        else if (hfType.First() == "2")
                        {
                            var dept = from c in documentUnionPubEmplList where c.FDocId == docObj.FDocId && c.FDeptNo != docObj.FDeptNo select c;//所有合发部门,不包括本部门
                            decimal AvgScore = 0;//定义平均分
                            AvgScore = Math.Round(decUnionScore / (dept.Count() + 1), 2);
                            //加上本部门
                            docHfScoreModel = new Model.DocHfScore();
                            docHfScoreModel.FDocClsCd = docObj.FDocClsCd;
                            docHfScoreModel.FDeptNo = docObj.FDeptNo;
                            docHfScoreModel.FUnionScore = AvgScore;

                            docHfScoreList.Add(docHfScoreModel);
                            foreach (var obj in dept)//加上其它部门
                            {
                                docHfScoreModel = new Model.DocHfScore();
                                docHfScoreModel.FDocClsCd = docObj.FDocClsCd;
                                docHfScoreModel.FDeptNo = obj.FDeptNo;
                                docHfScoreModel.FUnionScore = AvgScore;
                                docHfScoreList.Add(docHfScoreModel);
                            }
                        }
                    }
                }
            }
            #endregion

            #region 统计部门合发数量（有合发情况，包括未录用）
            List<Model.DocHfScore> docHfScoreNum = new List<Model.DocHfScore>();//用于统计数量
            foreach (var docObj in listDocHFAll)
            {
                docHfScoreModel = new Model.DocHfScore();
                int intDept = listDeptAll.Where(c => c.FDeptNo == docObj.FDeptNo).Count();
                if (intDept > 0)//这个部门需要计算合发分才进行以下程序
                {
                    var dept = from c in documentUnionPubEmplList where c.FDocId == docObj.FDocId && c.FDeptNo != docObj.FDeptNo select c;//所有合发部门,不包括本部门
                    foreach (var obj in dept)//循环合发部门
                    {
                        docHfScoreModel = new Model.DocHfScore();
                        docHfScoreModel.FDocClsCd = docObj.FDocClsCd;
                        docHfScoreModel.FDeptNo = obj.FDeptNo;

                        //以下添加数量
                        docHfScoreNum.Add(docHfScoreModel);
                    }
                }
            }
            #endregion

            #region 先计算每个部门的进度，真实排序按照部门完成进度来排序

            foreach (Model.HRDept deptObject in listDeptNoVirtual)
            {
                string strDeptNo = deptObject.FDeptNo;
                decimal decLocalDoc = 0;//区局录用情况的总分
                decimal decSuperDoc = 0;//上级录用的分数，用于计算当前单位 上级录用的总分
                decimal intBaseScore = 0;//区局考核基数

                #region 部门区局录用情况

                if (intLocalCount > 0)//有区局录用信息类别
                {
                    //循环需要计算的区局录用考核栏目
                    for (int i = 0; i < arrayLocalDocClsCd.Length; i++)
                    {
                        string strDocClsCd = arrayLocalDocClsCd[i];
                        if (!ztzlDocClsCdList.Contains(strDocClsCd))//如果不是专题专栏及其子类
                        {
                            int intDocCount = 0;//录用的信息条数
                            int intDocCountNoUnion = 0;//未合发的录用信息条数
                            var docQuery = from c in listDoc where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                            if (docQuery.Count() > 0)//如果有录用的信息
                            {
                                intDocCount = docQuery.Count();//录用的篇数
                                decimal decScore = 0;//该类别的录用分数

                                //获取该类别的录用分数
                                var docScoreQuery = from c in listDocClsScore where c.FDocClsCd == strDocClsCd select c.FEnrollScore;
                                if (docScoreQuery.Count() > 0)
                                {
                                    decScore = docScoreQuery.First();
                                }
                                //计算合发的分数
                                decimal decHFScore = 0;
                                //独享（如果是独享的话，就是 未合发分数+合发独享的分数，即不用作任何处理）
                                //共享(如果共享的话，就是 未合发分数+合发平摊到的分数)
                                if (deptObject.FUnionScoreType == "2")
                                {
                                    int docHfCount = listDocHF.Where(c => c.FDeptNo == strDeptNo && c.FDocClsCd == strDocClsCd).ToList().Count();//录用的信息合发条数
                                    //var dochfcount = from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                    intDocCountNoUnion = intDocCount - docHfCount;//获得未合发的信息条数

                                }
                                //获取当前部门、当前考核栏目所得到的合发分数
                                decHFScore = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();


                                decimal sumScore = intDocCountNoUnion * decScore + decHFScore;//未合发数量*单篇分数+合发分数
                                decimal intScore = Math.Round(sumScore * 100, 2) / 100;

                                decLocalDoc += sumScore;//区局录用总分增加

                            }
                            else//如果无录用的信息
                            {
                                //获取合发信息的分数
                                decimal decHFScore = 0;
                                decHFScore = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();
                                decLocalDoc += decHFScore;//区局录用总分增加
                            }
                        }
                        ///////////////////////////专题专栏分隔线/////////////////////////////////////////
                        else//如果是专题专栏或其子类，所有子类分数合并到本级下面
                        {

                            int ztzlDoc = 0;//专题专栏分数
                            foreach (string ztzlstrDocClsCd in ztzlDocClsCdList)
                            {

                                int intDocCount = 0;//录用的信息条数
                                int intDocCountNoUnion = 0;//未合发的录用信息条数
                                var docQuery = from c in listDoc where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                if (docQuery.Count() > 0)//如果有录用的信息
                                {
                                    intDocCount = docQuery.Count();//录用的篇数
                                    decimal decScore = 0;//该类别的录用分数

                                    //获取该类别的录用分数
                                    var docScoreQuery = from c in listDocClsScore where c.FDocClsCd == ztzlstrDocClsCd select c.FEnrollScore;
                                    if (docScoreQuery.Count() > 0)
                                    {
                                        decScore = docScoreQuery.First();
                                    }
                                    //计算合发的分数
                                    decimal decHFScore = 0;
                                    //独享（如果是独享的话，就是 未合发分数+合发独享的分数，即不用作任何处理）
                                    //共享(如果共享的话，就是 未合发分数+合发平摊到的分数)
                                    if (deptObject.FUnionScoreType == "2")
                                    {
                                        int docHfCount = listDocHF.Where(c => c.FDeptNo == strDeptNo && c.FDocClsCd == ztzlstrDocClsCd).ToList().Count();//录用的信息合发条数
                                        //var dochfcount = from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                        intDocCountNoUnion = intDocCount - docHfCount;//获得未合发的信息条数

                                    }
                                    //获取当前部门、当前考核栏目所得到的合发分数
                                    decHFScore = (from c in docHfScoreList where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();


                                    decimal sumScore = intDocCountNoUnion * decScore + decHFScore;//未合发数量*单篇分数+合发分数
                                    decimal intScore = Math.Round(sumScore * 100, 2) / 100;

                                    decLocalDoc += sumScore;//区局录用总分增加
                                }
                                else//如果无录用的信息
                                {
                                    //获取合发信息的分数
                                    decimal decHFScore = 0;
                                    decHFScore = (from c in docHfScoreList where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();
                                    decLocalDoc += decHFScore;//区局录用总分增加
                                }
                            }
                            decLocalDoc += ztzlDoc;
                        }
                    }
                }



                #endregion

                #region 上报信息录用加分情况
                if (intChkCount > 0)//有上级录用情况
                {
                    //循环需要计算的上级录用栏目
                    for (int i = 0; i < arrayChkInfoClsCd.Length; i++)
                    {
                        string strChkInfoClsCd = arrayChkInfoClsCd[i];//栏目编号
                        string strChkType = arrayChkType[i];
                        decimal docSumScore = 0;//总分
                        //慈溪按篇计的代码已经没用了，在后面另有计算代码。
                        if (strChkType == "1")//按篇计
                        {
                            decimal decScore = 0;//每篇的分数

                            int intDocCount = 0;//被录用的信息条数
                            //获取每篇的分数
                            var stdScoreQuery = from c in listChkInfoCls where c.FInfoClsNo == strChkInfoClsCd select c.FStdScore;
                            if (stdScoreQuery.Count() > 0)
                            {
                                decScore = stdScoreQuery.First().Value;
                            }

                            //获取上级录用信息的条数
                            var docCountQuery = from c in chkInfoAuditManual where c.FDeptNo == strDeptNo && c.FInfoClsNo == strChkInfoClsCd select c.FInfoID;

                            if (docCountQuery.Count() > 0)
                            {
                                intDocCount = docCountQuery.Count();
                            }

                            docSumScore = intDocCount * decScore;//该栏目总分                                                   

                        }
                        else if (strChkType == "2")//手动输入
                        {
                            //获取所有的分数
                            var docScoreQuery = from c in chkInfoAuditManual where c.FDeptNo == strDeptNo && c.FInfoClsNo == strChkInfoClsCd && null != c.FScore select c.FScore;
                            if (docScoreQuery.Count() > 0)
                            {
                                foreach (var decscore in docScoreQuery)
                                {
                                    docSumScore += decscore.Value;//该手动录入的分数总分
                                }
                            }
                            int t = 0;

                            if (t == 0)
                            {
                                //decSDLL += docSumScore;//所有手动录入的分数总分
                            }

                        }

                        decimal intSumScore = Math.Round(docSumScore * 100, 2) / 100;

                        decSuperDoc += intSumScore;//增加本部门 上级录用的总分

                    }
                }
                #endregion

                #region 考核基数
                //有区局录用情况则增加区局录用考核

                if (intLocalCount > 0)
                {
                    decimal decBaseScore = 0;
                    //if (decQuarter == 1)
                    //{
                    //    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore1;//获取该部门的考核基数
                    //    if (localBaseScore.Count() > 0)
                    //    {
                    //        decBaseScore = localBaseScore.First();
                    //    }
                    //}
                    //else if (decQuarter == 2)
                    //{
                    //    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore2;//获取该部门的考核基数
                    //    if (localBaseScore.Count() > 0)
                    //    {
                    //        decBaseScore = localBaseScore.First();
                    //    }
                    //}
                    //else if (decQuarter == 3)
                    //{
                    //    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore3;//获取该部门的考核基数
                    //    if (localBaseScore.Count() > 0)
                    //    {
                    //        decBaseScore = localBaseScore.First();
                    //    }
                    //}
                    //else if (decQuarter == 4)
                    //{
                    //    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore4;//获取该部门的考核基数
                    //    if (localBaseScore.Count() > 0)
                    //    {
                    //        decBaseScore = localBaseScore.First();
                    //    }
                    //}
                    //else
                    //{
                    //    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore;//获取该部门的考核基数
                    //    if (localBaseScore.Count() > 0)
                    //    {
                    //        decBaseScore = localBaseScore.First().Value;
                    //    }
                    //}
                    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore;//获取该部门的考核基数
                    if (localBaseScore.Count() > 0)
                    {
                        decBaseScore = localBaseScore.First().Value;
                    }
                    //考核基数
                    intBaseScore = Math.Round(decBaseScore * 100, 2) / 100;
                }
                #endregion

                decimal decWCJD = 0;
                if (intBaseScore != 0)
                {
                    decWCJD = Math.Round((decLocalDoc + decSuperDoc) / intBaseScore * 100, 2);
                }
                else
                {
                    decWCJD = -1;
                }
                deptObject.FDeptSchedule = decWCJD;
            }
            listDeptNoVirtual = (from c in listDeptNoVirtual
                                 orderby c.FIsAgency, c.FDeptSchedule descending, c.FSeq
                                 select c).ToList();
            #endregion

            #region 循环部门，绑定各部门的数字
            int deptCount = 0;

            foreach (Model.HRDept deptObject in listDeptNoVirtual)
            {
                //增加员工行时，以下1条数据都要置0，或重新实例化
                decimal decLocalDoc = 0;//区局录用情况的总分
                decimal decLocalDocCount = 0;//区局录用情况总数量

                decimal decSuperDoc = 0;//上级录用的分数，用于计算当前单位 上级录用的总分
                decimal decChkInfoSuperSum = 0;//所有按篇计的上级栏目录入的总篇数,用于计算上级录用加分

                rowIndex++;

                deptCount++;
                string strDeptNo = deptObject.FDeptNo;
                #region 序号

                string strXH = deptCount.ToString();

                xm = new Model.XlsModel();
                xm.Title = strXH;
                xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xm.RowIndex = rowIndex;
                xlsModels.Add(xm);

                #endregion

                #region 部门名称
                xm = new Model.XlsModel();
                xm.Title = deptObject.FDeptName;
                xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xm.RowIndex = rowIndex;
                xlsModels.Add(xm);

                #endregion

                #region 投稿数量

                int deptDocCount = 0;//部门投稿数量
                var deptDoc = from c in listDocAll where c.FDeptNo == strDeptNo select c.FDeptNo;
                if (deptDoc.Count() > 0)
                {
                    deptDocCount = deptDoc.Count();
                }
                int intHfCount = docHfScoreNum.Where(c => c.FDeptNo == strDeptNo).Count();

                intQjTGSL += deptDocCount + intHfCount;//增加全局投稿数量

                xm = new Model.XlsModel();
                xm.Title = (deptDocCount + intHfCount).ToString();//部门投稿数量=部门发布数量+部门合发数量
                xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xm.RowIndex = rowIndex;
                xlsModels.Add(xm);

                #endregion

                #region 部门区局录用情况

                if (intLocalCount > 0)//有区局录用信息类别
                {
                    //循环需要计算的区局录用考核栏目
                    for (int i = 0; i < arrayLocalDocClsCd.Length; i++)
                    {
                        string strDocClsCd = arrayLocalDocClsCd[i];
                        if (!ztzlDocClsCdList.Contains(strDocClsCd))//如果不是专题专栏及其子类
                        {
                            int intDocCount = 0;//录用的信息条数
                            int intDocCountNoUnion = 0;//未合发的录用信息条数
                            var docQuery = from c in listDoc where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                            if (docQuery.Count() > 0)//如果有录用的信息
                            {
                                intDocCount = docQuery.Count();//录用的篇数
                                decimal decScore = 0;//该类别的录用分数

                                //获取该类别的录用分数
                                var docScoreQuery = from c in listDocClsScore where c.FDocClsCd == strDocClsCd select c.FEnrollScore;
                                if (docScoreQuery.Count() > 0)
                                {
                                    decScore = docScoreQuery.First();
                                }
                                //计算合发的分数
                                decimal decHFScore = 0;
                                //独享（如果是独享的话，就是 未合发分数+合发独享的分数，即不用作任何处理）
                                //共享(如果共享的话，就是 未合发分数+合发平摊到的分数)
                                if (deptObject.FUnionScoreType == "2")
                                {
                                    int docHfCount = listDocHF.Where(c => c.FDeptNo == strDeptNo && c.FDocClsCd == strDocClsCd).ToList().Count();//录用的信息合发条数
                                    //var dochfcount = from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                    intDocCountNoUnion = intDocCount - docHfCount;//获得未合发的信息条数

                                }
                                //获取当前部门、当前考核栏目所得到的合发分数
                                decHFScore = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();


                                decimal sumScore = intDocCountNoUnion * decScore + decHFScore;//未合发数量*单篇分数+合发分数
                                decimal intScore = Math.Round(sumScore * 100, 2) / 100;

                                int intDocHFCount = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c).ToList().Count();//通过其他部门合发的 信息数量

                                xm = new Model.XlsModel();
                                xm.Title = (intDocCountNoUnion + intDocHFCount).ToString();
                                xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                                xm.RowIndex = rowIndex;
                                xlsModels.Add(xm);

                                decLocalDoc += sumScore;//区局录用总分增加
                                decLocalDocCount += (intDocCountNoUnion + intDocHFCount);//区局录用总数量增加
                                decQjLocalScore[i] += sumScore;//增加全局的区局录用情况该子栏目的总分
                                decQjLocalNum[i] += (intDocCountNoUnion + intDocHFCount);//增加全局的区局录用情况该子栏目的总篇数

                            }
                            else//如果无录用的信息
                            {
                                //获取合发信息的分数
                                decimal decHFScore = 0;
                                decHFScore = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();
                                int intDocHFCount = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c).ToList().Count();//通过其他部门合发的 信息数量

                                xm = new Model.XlsModel();
                                xm.Title = intDocHFCount.ToString();
                                xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                                xm.RowIndex = rowIndex;
                                xlsModels.Add(xm);

                                decLocalDoc += decHFScore;//区局录用总分增加
                                decLocalDocCount += intDocHFCount;//区局录用总数量增加
                                decQjLocalScore[i] += decHFScore;//增加全局的区局录用情况该子栏目的总分
                                //decQjLocalScore[i] += 0;//增加全局的区局录用情况该子栏目的总分
                                decQjLocalNum[i] += intDocHFCount;//增加全局的区局录用情况该子栏目的总篇数
                            }
                        }
                        ///////////////////////////专题专栏分隔线/////////////////////////////////////////
                        else//如果是专题专栏或其子类，所有子类分数合并到本级下面
                        {

                            int ztzlDoc = 0;//专题专栏分数
                            foreach (string ztzlstrDocClsCd in ztzlDocClsCdList)
                            {

                                int intDocCount = 0;//录用的信息条数
                                int intDocCountNoUnion = 0;//未合发的录用信息条数
                                var docQuery = from c in listDoc where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                if (docQuery.Count() > 0)//如果有录用的信息
                                {
                                    intDocCount = docQuery.Count();//录用的篇数
                                    decimal decScore = 0;//该类别的录用分数

                                    //获取该类别的录用分数
                                    var docScoreQuery = from c in listDocClsScore where c.FDocClsCd == ztzlstrDocClsCd select c.FEnrollScore;
                                    if (docScoreQuery.Count() > 0)
                                    {
                                        decScore = docScoreQuery.First();
                                    }
                                    //计算合发的分数
                                    decimal decHFScore = 0;
                                    //独享（如果是独享的话，就是 未合发分数+合发独享的分数，即不用作任何处理）
                                    //共享(如果共享的话，就是 未合发分数+合发平摊到的分数)
                                    if (deptObject.FUnionScoreType == "2")
                                    {
                                        int docHfCount = listDocHF.Where(c => c.FDeptNo == strDeptNo && c.FDocClsCd == ztzlstrDocClsCd).ToList().Count();//录用的信息合发条数
                                        //var dochfcount = from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c.FDeptNo;
                                        intDocCountNoUnion = intDocCount - docHfCount;//获得未合发的信息条数

                                    }
                                    //获取当前部门、当前考核栏目所得到的合发分数
                                    decHFScore = (from c in docHfScoreList where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();


                                    decimal sumScore = intDocCountNoUnion * decScore + decHFScore;//未合发数量*单篇分数+合发分数
                                    decimal intScore = Math.Round(sumScore * 100, 2) / 100;

                                    int intDocHFCount = (from c in docHfScoreList where c.FDocClsCd == strDocClsCd && c.FDeptNo == strDeptNo select c).ToList().Count();//通过其他部门合发的 信息数量
                                    //sbr.Append("<td align=\"center\">");
                                    //sbr.Append((intDocCountNoUnion + intDocHFCount).ToString());//数量=发布数量（排除合发的自己发布的信息）+合发数量(包括自己发布的合发信息)
                                    //sbr.Append("</td>");
                                    ztzlDoc += intDocCountNoUnion + intDocHFCount;

                                    decLocalDoc += sumScore;//区局录用总分增加
                                    decLocalDocCount += (intDocCountNoUnion + intDocHFCount);//区局录用总数量增加
                                    decQjLocalScore[i] += sumScore;//增加全局的区局录用情况该子栏目的总分
                                    decQjLocalNum[i] += (intDocCountNoUnion + intDocHFCount);//增加全局的区局录用情况该子栏目的总篇数

                                }
                                else//如果无录用的信息
                                {
                                    //获取合发信息的分数
                                    decimal decHFScore = 0;
                                    decHFScore = (from c in docHfScoreList where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c.FUnionScore).Sum();
                                    int intDocHFCount = (from c in docHfScoreList where c.FDocClsCd == ztzlstrDocClsCd && c.FDeptNo == strDeptNo select c).ToList().Count();//通过其他部门合发的 信息数量
                                    //sbr.Append("<td align=\"center\">" + intDocHFCount.ToString() + "</td>");
                                    ztzlDoc += intDocHFCount;
                                    decLocalDoc += decHFScore;//区局录用总分增加
                                    decLocalDocCount += intDocHFCount;//区局录用总数量增加
                                    decQjLocalScore[i] += decHFScore;//增加全局的区局录用情况该子栏目的总分
                                    //decQjLocalScore[i] += 0;//增加全局的区局录用情况该子栏目的总分
                                    decQjLocalNum[i] += intDocHFCount;//增加全局的区局录用情况该子栏目的总篇数
                                }
                            }

                            xm = new Model.XlsModel();
                            xm.Title = ztzlDoc.ToString();
                            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                            xm.RowIndex = rowIndex;
                            xlsModels.Add(xm);
                        }
                    }
                }


                #endregion

                #region 录用率
                //录用率=录用考核栏目总数/投稿数量
                decimal decLYL = 0;
                if ((deptDocCount + intHfCount) != 0)
                {
                    decLYL = Math.Round(decLocalDocCount / (deptDocCount + intHfCount) * 100, 2);
                }
                else
                {
                    decLYL = -1;
                }
                string strLYL = "";
                if (decLYL != -1)
                {
                    strLYL = string.Format("{0:F2}", decLYL) + "%";
                }

                xm = new Model.XlsModel();
                xm.Title = strLYL;
                xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xm.RowIndex = rowIndex;
                xlsModels.Add(xm);

                #endregion

                #region 上报信息录用加分情况
                if (intChkCount > 0)//有上级录用情况
                {
                    //循环需要计算的上级录用栏目
                    for (int i = 0; i < arrayChkInfoClsCd.Length; i++)
                    {
                        string strChkInfoClsCd = arrayChkInfoClsCd[i];//栏目编号
                        string strChkType = arrayChkType[i];
                        decimal docSumScore = 0;//总分
                        //慈溪按篇计的代码已经没用了，在后面另有计算代码。
                        if (strChkType == "1")//按篇计
                        {
                            int intDocCount = 0;//被录用的信息条数

                            docSumScore = GetCountByFDocClsCdType1(listChkInfoCls, chkInfoAuditManual, strChkInfoClsCd, strDeptNo, ref intDocCount);//该栏目总分                            
                            decChkInfoSuperSum += intDocCount;//所有按篇计的上级栏目录入的总篇数,用于计算上级录用加分                           

                            //判断该栏目在哪一个考核栏目中
                            //for (int j = 0; j < arrayCheckChkNo.Length; j++)
                            //{
                            //    string strChkInfoNos = arrayCheckChkNo[j];
                            //    string[] arrayExisChkInfoNo = strChkInfoNos.Split(',');
                            //    if (arrayExisChkInfoNo.Contains(strChkInfoClsCd))//如果存在该编号，则相应的考核总数相加
                            //    {
                            //        //arrayDecSuperDoc[j] += docSumScore;
                            //        break;
                            //    }
                            //}

                        }
                        else if (strChkType == "2")//手动输入
                        {
                            //获取所有的分数
                            docSumScore = GetCountByFDocClsCdType2(listChkInfoCls, chkInfoAuditManual, strChkInfoClsCd, strDeptNo);

                            int t = 0;

                            ////判断该栏目在哪一个考核栏目中,如果一级栏目计分是手动录入，则不包含在考核任务中，二级栏目需要判断
                            //for (int j = 0; j < arrayCheckChkNo.Length; j++)
                            //{
                            //    string strChkInfoNos = arrayCheckChkNo[j];
                            //    string[] arrayExisChkInfoNo = strChkInfoNos.Split(',');
                            //    if (arrayExisChkInfoNo.Contains(strChkInfoClsCd))//如果存在该编号，则相应的考核总数相加
                            //    {
                            //        //arrayDecSuperDoc[j] += docSumScore;
                            //        t = 1;
                            //        break;
                            //    }
                            //}

                            if (t == 0)
                            {
                                //decSDLL += docSumScore;//所有手动录入的分数总分
                            }

                        }

                        decimal intSumScore = Math.Round(docSumScore * 100, 2) / 100;

                        xm = new Model.XlsModel();
                        xm.Title = string.Format("{0:F2}", intSumScore);
                        xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                        xm.RowIndex = rowIndex;
                        xlsModels.Add(xm);

                        decSuperDoc += intSumScore;//增加本部门 上级录用的总分
                        decQjSuperScore[i] += intSumScore;//增加全局的上级录用情况的每个栏目总分

                    }
                }
                #endregion

                #region 积分累计(本级+上级)

                xm = new Model.XlsModel();
                xm.Title = (decLocalDoc + decSuperDoc).ToString();
                xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xm.RowIndex = rowIndex;
                xlsModels.Add(xm);

                #endregion

                #region 考核基数
                decimal intBaseScore = 0;
                //本级
                if (intLocalCount > 0)
                {
                    decimal decBaseScoreLocal = 0;

                    var localBaseScore = from c in listChkInfoStdLocal where c.FDeptNo == strDeptNo select c.FBaseScore;//获取该部门的本级基分
                    if (localBaseScore.Count() > 0)
                    {
                        decBaseScoreLocal = localBaseScore.First().Value;
                    }
                    //考核基数
                    intBaseScore += Math.Round(decBaseScoreLocal * 100, 2) / 100;
                }
                //上级
                if (intChkCount > 0)
                {
                    decimal decBaseScoreSuper = 0;
                    var superBaseScore = from c in listChkInfoStdSuper where c.FDeptNo == strDeptNo select c.FBaseScore;//获取该部门的上级基分
                    if (superBaseScore.Count() > 0)
                    {
                        decBaseScoreSuper = superBaseScore.First().Value;
                    }
                    //考核基数
                    intBaseScore += Math.Round(decBaseScoreSuper * 100, 2) / 100;
                }
                xm = new Model.XlsModel();
                xm.Title = intBaseScore.ToString();
                xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xm.RowIndex = rowIndex;
                xlsModels.Add(xm);

                decQjKHJS += intBaseScore;//增加全局考核基数
                #endregion

                #region 完成进度
                decimal decWCJD = 0;
                if (intBaseScore != 0)
                {
                    decWCJD = Math.Round((decLocalDoc + decSuperDoc) / intBaseScore * 100, 2);
                }
                else
                {
                    decWCJD = -1;
                }
                string strWCJD = "";
                if (decWCJD != -1)
                {
                    strWCJD = string.Format("{0:F2}", decWCJD) + "%";
                }

                xm = new Model.XlsModel();
                xm.Title = strWCJD;
                xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xm.RowIndex = rowIndex;
                xlsModels.Add(xm);
                #endregion
            }
            #endregion

            #region 合计行
            rowIndex++;

            //排序号
            deptCount++;

            xm = new Model.XlsModel();
            xm.Title = deptCount.ToString();
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xlsModels.Add(xm);

            //单位
            xm = new Model.XlsModel();
            xm.Title = "合计";
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xlsModels.Add(xm);

            //投稿数量
            xm = new Model.XlsModel();
            xm.Title = intQjTGSL.ToString();
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xlsModels.Add(xm);

            //本级录用情况
            decimal intQjLocalNumSum = 0;
            if (intLocalCount > 0)
            {
                //循环需要计算的区局录用信息编号
                for (int i = 0; i < arrayLocalDocClsCd.Length; i++)
                {
                    decimal intQjLocalNum = Math.Round(decQjLocalNum[i] * 100, 2) / 100;

                    xm = new Model.XlsModel();
                    xm.Title = intQjLocalNum.ToString();
                    xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                    xm.RowIndex = rowIndex;
                    xlsModels.Add(xm);

                    intQjLocalNumSum += intQjLocalNum;//合计全局 本级录用情况分数
                }
            }

            //录用率
            decimal decQjLYL = 0;
            if (intQjTGSL != 0)
            {
                decQjLYL = Math.Round(intQjLocalNumSum / intQjTGSL * 100, 2);
            }
            else
            {
                decQjLYL = -1;
            }
            string strQjLYL = "";
            if (decQjLYL != -1)
            {
                strQjLYL = string.Format("{0:F2}", decQjLYL) + "%";
            }
            xm = new Model.XlsModel();
            xm.Title = strQjLYL;
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xlsModels.Add(xm);

            //上报信息录用加分情况
            if (intChkCount > 0)
            {
                //循环需要计算的上级录用栏目
                for (int i = 0; i < arrayChkInfoClsCd.Length; i++)
                {
                    xm = new Model.XlsModel();
                    xm.Title = string.Format("{0:F2}", decQjSuperScore[i]);
                    xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
                    xm.RowIndex = rowIndex;
                    xlsModels.Add(xm);
                }
            }

            //积分累计
            decimal intQjScoreSum = 0;
            //本级
            if (intLocalCount > 0)
            {
                //循环需要计算的区局录用信息编号
                for (int i = 0; i < arrayLocalDocClsCd.Length; i++)
                {
                    decimal intQjLocalScore = Math.Round(decQjLocalScore[i] * 100, 2) / 100;
                    intQjScoreSum += intQjLocalScore;
                }
            }
            //上级
            if (intChkCount > 0)
            {
                //循环需要计算的上级录用信息
                for (int i = 0; i < arrayChkInfoClsCd.Length; i++)
                {
                    decimal intQjSuperScore = Math.Round(decQjSuperScore[i] * 100, 2) / 100;
                    intQjScoreSum += intQjSuperScore;
                }
            }
            xm = new Model.XlsModel();
            xm.Title = intQjScoreSum.ToString();
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xlsModels.Add(xm);

            //考核基数
            xm = new Model.XlsModel();
            xm.Title = decQjKHJS.ToString();
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xlsModels.Add(xm);

            //完成进度
            decimal decQjWCJD = 0;
            if (decQjKHJS != 0)
            {
                decQjWCJD = Math.Round(intQjScoreSum / decQjKHJS * 100, 2);
            }
            else
            {
                decQjWCJD = -1;
            }
            string strQjWCJD = "";
            if (decQjWCJD != -1)
            {
                strQjWCJD = string.Format("{0:F2}", decQjWCJD) + "%";
            }
            xm = new Model.XlsModel();
            xm.Title = strQjWCJD;
            xm.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xm.RowIndex = rowIndex;
            xlsModels.Add(xm);

            #endregion

            #endregion



            return xlsModels;
        }

        #endregion


        /// <summary>
        /// 获取当前栏目及其子栏目的分数(按篇计)
        /// </summary>
        /// <returns></returns>
        private decimal GetCountByFDocClsCdType1(List<Model.ChkInfoCls> listChkInfoCls, List<Model.ChkInfoAuditManual> chkInfoAuditManual, string strChkInfoClsCd, string strDeptNo, ref int DocCount)
        {
            decimal decScore = 0;//每篇的分数
            int intDocCount = 0;//被录用的信息条数
            decimal docSumScore = 0;//总分

            //获取每篇的分数
            var stdScoreQuery = from c in listChkInfoCls where c.FInfoClsNo == strChkInfoClsCd select c.FStdScore;
            if (stdScoreQuery.Count() > 0)
            {
                decScore = stdScoreQuery.First().Value;
            }

            //获取上级录用信息的条数
            var docCountQuery = from c in chkInfoAuditManual where c.FDeptNo == strDeptNo && c.FInfoClsNo == strChkInfoClsCd select c.FInfoID;

            if (docCountQuery.Count() > 0)
            {
                intDocCount = docCountQuery.Count();
            }

            DocCount += intDocCount;//该栏目总数
            docSumScore += intDocCount * decScore;//该栏目总分

            var childChkInfo = from c in listChkInfoCls where c.FPreInfoClsNo == strChkInfoClsCd && c.FisExamine == "Y" select c;
            if (childChkInfo.Count() > 0)
            {
                foreach (Model.ChkInfoCls chkInfoClsObject in childChkInfo)
                {
                    docSumScore += GetCountByFDocClsCdType1(listChkInfoCls, chkInfoAuditManual, chkInfoClsObject.FInfoClsNo, strDeptNo, ref DocCount);
                }
            }

            return docSumScore;
        }




        /// <summary>
        /// 获取当前栏目及其子栏目的分数(按分计)
        /// </summary>
        /// <returns></returns>
        private decimal GetCountByFDocClsCdType2(List<Model.ChkInfoCls> listChkInfoCls, List<Model.ChkInfoAuditManual> chkInfoAuditManual, string strChkInfoClsCd, string strDeptNo)
        {
            decimal docSumScore = 0;//总分

            var docScoreQuery = from c in chkInfoAuditManual where c.FDeptNo == strDeptNo && c.FInfoClsNo == strChkInfoClsCd && null != c.FScore select c.FScore;
            if (docScoreQuery.Count() > 0)
            {
                foreach (var decscore in docScoreQuery)
                {
                    docSumScore += decscore.Value;//该手动录入的分数总分
                }
            }

            var childChkInfo = from c in listChkInfoCls where c.FPreInfoClsNo == strChkInfoClsCd && c.FisExamine == "Y" select c;
            if (childChkInfo.Count() > 0)
            {
                foreach (Model.ChkInfoCls chkInfoClsObject in childChkInfo)
                {
                    docSumScore += GetCountByFDocClsCdType2(listChkInfoCls, chkInfoAuditManual, chkInfoClsObject.FInfoClsNo, strDeptNo);
                }
            }
            return docSumScore;
        }


    }
}
